Skip to content

Commit 36d933d

Browse files
authored
Update read-n-characters-given-read4.py
1 parent 1051edf commit 36d933d

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

Python/read-n-characters-given-read4.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ def read(self, buf, n):
3737
"""
3838
read_bytes = 0
3939
buffer = [''] * 4
40-
globalN = n
4140
for i in xrange(n / 4 + 1):
4241
size = read4(buffer)
4342
if size:
44-
toRead = min(globalN,size)
45-
buf[read_bytes:read_bytes+toRead] = buffer[:toRead]
46-
read_bytes += toRead
47-
globalN -= toRead
43+
to_read = min(n-read_bytes, size)
44+
buf[read_bytes:read_bytes+to_read] = buffer[:to_read]
45+
read_bytes += to_read
4846
else:
4947
break
5048
return read_bytes

0 commit comments

Comments
 (0)