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 josh.r
Recipients Don Hatch, josh.r, martin.panter, serhiy.storchaka
Date 2020-11-20.18:48:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1605898124.5.0.162185282894.issue26290@roundup.psfhosted.org>
In-reply-to
Content
For those who find this in the future, the simplest workaround for the:

for line in sys.stdin:

issue on Python 2 is to replace it with:

for line in iter(sys.stdin.readline, ''):

The problem is caused by the way file.__next__'s buffering behaves, but file.readline doesn't use that code (it delegates to either fgets or a loop over getc/getc_unlocked that never overbuffers beyond the newline). Two-arg iter lets you make an iterator that calls readline each time you want a line, and considers a return of '' (which is what readline returns when you hit EOF) to terminate iteration.
History
Date User Action Args
2020-11-20 18:48:44josh.rsetrecipients: + josh.r, martin.panter, serhiy.storchaka, Don Hatch
2020-11-20 18:48:44josh.rsetmessageid: <1605898124.5.0.162185282894.issue26290@roundup.psfhosted.org>
2020-11-20 18:48:44josh.rlinkissue26290 messages
2020-11-20 18:48:44josh.rcreate