with open(r"a.txt","r") as f:
print("文件名是:{0}".format(f.name))#熟悉name
print(f.tell())#读取指针位置
print("读取的内容:{0}".format(f.read()))
print(f.tell()) # 读取指针位置
f.seek(3,2)
print("读取的内容:{0}".format(f.read()))
C:\Users\pcl\venv\Scripts\python.exe "C:/Users/pcl/.1aPython all exercise/文件/seek.py"
Traceback (most recent call last):
File "C:\Users\pcl\.1aPython all exercise\文件\seek.py", line 6, in <module>
f.seek(3,2)
io.UnsupportedOperation: can't do nonzero end-relative seeks
文件名是:a.txt
0
读取的内容:pcl龙龙龙龙大帅逼龙龙大帅逼sdsfag #0 #0
bei京外国语大学 #1 #1
永远的白月光 #2 #2
84
Process finished with exit code 1
老师 这是怎么回事 seek(3)就没事,seek(3,1)就不行