【发布时间】:2011-08-14 05:17:57
【问题描述】:
我正在尝试重复读取系统日志,并且只从我上次阅读的中断点开始。我正在尝试保存 tell() 的位置是一个单独的文件,并在每次读取之前重新加载以查找。
lf = open("location.file", 'r')
s = lf.readline()
last_pos = int(s.strip())
lf.close()
sl = open("/var/log/messages", 'r')
sl.seek(last_pos)
for line in sl.readlines():
# This should be the starting point from the last read
last_loc = sl.tell()
lf = open("location.file", "w+")
lf.write(last_loc)
lf.close()
【问题讨论】: