私はsyslogを繰り返し読み込もうとしています。 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()
try: \t with open("location.file") as lf: \t \t s = lf.read() \t \t last_pos = int(s) except: \t \t last_pos = 0;
–コメントにバッククッキーを使用する必要がありますが、そうでなければ良い提案です。 – agf