Message162903
First off, I'm a complete noob looking at the python source code for the first time so forgive me if I've done something wrong.
What if the length of the chunk is checked as well? The following code works fine:
import sys
while True:
chunk = sys.stdin.read(1000)
if not chunk:
break
# process
if len(chunk) < 1000:
break
Something similar could be done in the fileinput class. The patch I've attached checks if the number of bytes read from the file is less than the size of the buffer (which means that the file has ended). If so, the next time the file is to be read it skips to the next file instead.
joey@j-Laptop:~/cpython$ ./python
Python 3.3.0a3+ (default:befd56673c80+, Jun 15 2012, 17:14:12)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fileinput
[73732 refs]
>>> lines = list(fileinput.input())
foo
bar
^D
[73774 refs]
>>> lines
['foo\n', 'bar\n']
[73780 refs] |
|
Date |
User |
Action |
Args |
2012-06-15 14:20:35 | jgeralnik | set | recipients:
+ jgeralnik, jaraco, pitrou, Arfrever, r.david.murray, docs@python, zach.ware, serhiy.storchaka |
2012-06-15 14:20:34 | jgeralnik | set | messageid: <1339770034.92.0.432946035346.issue15068@psf.upfronthosting.co.za> |
2012-06-15 14:20:34 | jgeralnik | link | issue15068 messages |
2012-06-15 14:20:34 | jgeralnik | create | |
|