Message325995
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? |
|
Date |
User |
Action |
Args |
2018-09-21 15:41:31 | ChrisRands | set | recipients:
+ ChrisRands, docs@python |
2018-09-21 15:41:31 | ChrisRands | set | messageid: <1537544491.72.0.956365154283.issue34764@psf.upfronthosting.co.za> |
2018-09-21 15:41:31 | ChrisRands | link | issue34764 messages |
2018-09-21 15:41:31 | ChrisRands | create | |
|