首页 > 代码库 > 2.11 读取流数据源

2.11 读取流数据源

import time
import os
import sys

if len(sys.argv)!=2:
print >> sys.stderr ,"Please specify filename to read"
filename = sys.argv[1]

if not os.path.isfile(filename):
print >> sys.stderr ,"Given file: \"%s\" is not a file" % filename

with open(filename,‘r‘) as f:
filesize = os.stat(filename)[6]
f.seek(filesize)

while True:
where = f.tell()
line = f.readline()
if not line:
time.sleep(where)
else:
print line

2.11 读取流数据源