标签:style count odi col __next__ while tail yield open
生成器
def yasuo(): for i in range(2000000): yield ‘亚索%s‘%i g = yasuo() count = 0 for i in g : count += 1 print(i) if count > 50: break # print(‘******‘,g.__next__()) for i in g : count += 1 print(i) if count > 100: break
监听文件输入的例子
def tail(filename): f = open(filename,encoding=‘utf-8‘) while True: line = f.readline() if line.strip(): yield line.strip() g = tail(‘file‘) for i in g: if ‘python‘ in i: print(‘***‘,i)
标签:style count odi col __next__ while tail yield open
原文地址:https://www.cnblogs.com/8856S/p/9741006.html