這是我通過使用f.seek()方法尋找位置來從文件中獲取行的代碼,但我得到了錯誤的輸出。它從第一行的中間打印。 可以幫我解決這個問題嗎?如何通過從python中的另一個文本文件尋找位置來打印文件中的行?
f=open(r"sample_text_file","r")
last_pos=int(f.read())
f1=open(r"C:\Users\ddadi\Documents\project2\check\log_file3.log","r")
f1.seek(last_pos)
for i in f1:
print i
last_position=f1.tell()
with open('sample_text.txt', 'a') as handle:
handle.write(str(last_position))
sample_text文件中包含的文件指針偏移量由f1.tell()
你是怎麼得到神奇的人物'419490'的? –
請提供樣本輸入,當前輸出和預期輸出。否則,包括我在內的人會很難幫助你。 – jockster
確定實際上我通過使用f.tell()方法得到了該值,並且我剛剛從該文本文件中存儲了一個文本文件我正在讀取該值@Nehal J Wani – surya