4.1 手动遍历迭代器
问题
解决方案
def manual_iter():
with open('/etc/passwd') as f:
try:
while True:
line = next(f)
print(line, end='')
except StopIteration:
pass
# same
with open('/etc/passwd') as f:
while True:
line = next(f, None)
if line is None:
break
print(line, end='')讨论
Last updated