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 ChrisRands
Recipients ChrisRands, docs@python
Date 2018-09-21.15:41:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1537544491.72.0.956365154283.issue34764@psf.upfronthosting.co.za>
In-reply-to
Content
This arose from this SO question: https://stackoverflow.com/questions/52446415/line-in-iterfp-readline-rather-than-line-in-fp 

The example given in the docs:

with open('mydata.txt') as fp:
    for line in iter(fp.readline, ''):
        process_line(line)

Is exactly equivalent to the following because an empty string is only returned by readline at the EOF:

with open('mydata.txt') as fp:
    for line in fp:
        process_line(line)

The empty string '' sentinel value could be changed to another value to provide a possibly more meaningful example where the 2nd code snippet would not always produce the same result?
History
Date User Action Args
2018-09-21 15:41:31ChrisRandssetrecipients: + ChrisRands, docs@python
2018-09-21 15:41:31ChrisRandssetmessageid: <1537544491.72.0.956365154283.issue34764@psf.upfronthosting.co.za>
2018-09-21 15:41:31ChrisRandslinkissue34764 messages
2018-09-21 15:41:31ChrisRandscreate