This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jgeralnik
Recipients Arfrever, docs@python, jaraco, jgeralnik, pitrou, r.david.murray, serhiy.storchaka, zach.ware
Date 2012-06-15.14:20:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1339770034.92.0.432946035346.issue15068@psf.upfronthosting.co.za>
In-reply-to
Content
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]
History
Date User Action Args
2012-06-15 14:20:35jgeralniksetrecipients: + jgeralnik, jaraco, pitrou, Arfrever, r.david.murray, docs@python, zach.ware, serhiy.storchaka
2012-06-15 14:20:34jgeralniksetmessageid: <1339770034.92.0.432946035346.issue15068@psf.upfronthosting.co.za>
2012-06-15 14:20:34jgeralniklinkissue15068 messages
2012-06-15 14:20:34jgeralnikcreate