1.手动遍历迭代器 使用next函数,并捕获StopIteration异常. def manual_iter(): with open('./test.py') as f: try: while True: line = next(f) print line except StopIteration: pass next函数也可以指定值来标记结尾 def manual_iter(): with open('./test.py') as f: try: while True: line = nex…