修改代码错误
next(iterator[, default])如果没有设置默认值,迭代结束的时候仍然会抛出StopIteration异常
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
|
||||
with open('/etc/passwd') as f:
|
||||
while True:
|
||||
line = next(f)
|
||||
line = next(f, None)
|
||||
if line is None:
|
||||
break
|
||||
print(line, end='')
|
||||
|
||||
Reference in New Issue
Block a user