python文件的定位讀寫


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()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM