监听文件输入的例子

 1 def tail(filename):
 2     f = open(filename, encoding='utf-8')
 3     while 1:
 4         line = f.readline()
 5         if line.strip():
 6             yield line.strip()
 7 g = tail('file')
 8 for i in g:
 9     if 'python' in i:
10         print('***',i)

 

posted @ 2018-07-19 22:08  李培冠  阅读(266)  评论(0编辑  收藏  举报