【发布时间】:2020-06-21 21:03:59
【问题描述】:
如何在 python 中“关注”类似于 tail 命令的文件?例如,我认为以下内容会起作用:
def tail(filepath):
source = open(filepath)
source.seek(0,2)
while True:
chunk = source.readline()
yield chunk
source.close()
但是,当这些行被添加并保存到相关文件中时,它似乎并没有在“新行”上出现。在 python 中尾随文件的正确方法是什么?
【问题讨论】:
-
这能回答你的问题吗? Reading from a frequently updated file