这是我通过使用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