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;
–당신은 코멘트에 backticks를 사용해야하지만, 그렇지 않으면 좋은 제안. – agf