1.獲取當前讀寫的位置。在讀寫的過程中,如果想知道當前的位置,可以使用tell()來獲取
1 #打開一個已經存在的文件 2 f = open('test.txt','r') 3 str = f.read(3) 4 print("讀取的數據是:",str) 5 #查找當前位置 6 position = f.tell() 7 print("當前位置:",position) 8 9 str = f.read(6) 10 print("讀取的數據是:",str) 11 # 查找當前位置 12 position = f.tell() 13 print("當前文件位置 : ", position) 14 #關閉文件 15 f.close()