We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 8b0e903 + 49d2702 commit 43aa61eCopy full SHA for 43aa61e
cookbook/c04/p16_iterate_while.py
@@ -7,6 +7,10 @@
7
import sys
8
9
10
+def process_data():
11
+ print(data)
12
+
13
14
def reader(s, size):
15
while True:
16
data = s.recv(size)
@@ -22,11 +26,10 @@ def reader2(s, size):
22
26
23
27
def iterate_while():
24
28
CHUNKSIZE = 8192
25
- f = open('/etc/passwd')
- for chunk in iter(lambda: f.read(10), ''):
- n = sys.stdout.write(chunk)
29
+ with open('/etc/passwd') as f:
30
+ for chunk in iter(lambda: f.read(10), ''):
31
+ n = sys.stdout.write(chunk)
32
33
34
if __name__ == '__main__':
35
iterate_while()
-
0 commit comments