Use with open() to ensure the file gets close()d

`process_data()`is an undefined name in this context
This commit is contained in:
cclauss
2017-09-19 21:08:59 +08:00
committed by GitHub
parent 71a80a8f42
commit 05ca48e02e

View File

@@ -22,11 +22,10 @@ def reader2(s, size):
def iterate_while():
CHUNKSIZE = 8192
f = open('/etc/passwd')
for chunk in iter(lambda: f.read(10), ''):
n = sys.stdout.write(chunk)
with open('/etc/passwd') as f:
for chunk in iter(lambda: f.read(10), ''):
n = sys.stdout.write(chunk)
if __name__ == '__main__':
iterate_while()