for line in rest_lines:
code = chardet.detect(line).get('encoding')
line = line.decode(code).encode(sys.stdout.encoding)
sys.stdout.write(''.join([line.strip(), os.linesep]))
sys.stdout.flush()
except Exception, e:
print 'notice: open file with error({0})'.format(e)
exit()
print 'notice: start position is', seekps
while True:
try:
with open(target, 'r+b') as f:
f.seek(0, os.SEEK_END)
# 防止数据被意外截断
if f.tell()<seekps:
f.seek(f.tell())
else:
f.seek(seekps)
while True:
line = f.readline()
if not line.strip():
break
code = chardet.detect(line).get('encoding')
line = line.decode(code).encode(sys.stdout.encoding)
sys.stdout.write(''.join([line.strip(), os.linesep]))
sys.stdout.flush()
seekps = f.tell()
except Exception, e:
print 'notice: open file with error({0})'.format(e)
break