【发布时间】:2018-01-26 01:40:09
【问题描述】:
我正在使用 seek 函数在更新的文件中提取新行。我的代码如下所示:
read_data=open('path-to-myfile','r')
read_data.seek(0,2)
while True:
time.sleep(sometime)
new_data=read_data.readlines()
do something with new_data
myfile 是一个 csv 文件,会不断更新
问题是,通常在 while 内循环几次之后,new_data 什么都没有返回。它可以是不同的循环数。虽然我检查了我的文件,但它仍在更新......所以我的代码有什么问题吗?或者有没有其他方法可以做到这一点?
任何帮助表示赞赏!
【问题讨论】:
标签: python python-3.x io