Skip to content

Commit 05ca48e

Browse files
author
cclauss
authored
Use with open() to ensure the file gets close()d
`process_data()`is an undefined name in this context
1 parent 71a80a8 commit 05ca48e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

cookbook/c04/p16_iterate_while.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ def reader2(s, size):
2222

2323
def iterate_while():
2424
CHUNKSIZE = 8192
25-
f = open('/etc/passwd')
26-
for chunk in iter(lambda: f.read(10), ''):
27-
n = sys.stdout.write(chunk)
25+
with open('/etc/passwd') as f:
26+
for chunk in iter(lambda: f.read(10), ''):
27+
n = sys.stdout.write(chunk)
2828

2929

3030
if __name__ == '__main__':
3131
iterate_while()
32-

0 commit comments

Comments
 (0)