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 mgrazebrook
Recipients docs@python, mgrazebrook
Date 2011-02-09.20:40:44
SpamBayes Score 2.0914936e-12
Marked as misclassified No
Message-id <1297284045.4.0.795458647498.issue11163@psf.upfronthosting.co.za>
In-reply-to
Content
This code fragment from the documentation of iter() doesn't work as intended. Change "STOP" to "STOP\n". Maybe also check for EOF as it hangs.

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

Or maybe this makes a better example because it's clearer wha'ts going on:

square_generator = (i * i for i in range(100000))
for n in iter( square_generator.next, 144):
    print n
History
Date User Action Args
2011-02-09 20:40:45mgrazebrooksetrecipients: + mgrazebrook, docs@python
2011-02-09 20:40:45mgrazebrooksetmessageid: <1297284045.4.0.795458647498.issue11163@psf.upfronthosting.co.za>
2011-02-09 20:40:44mgrazebrooklinkissue11163 messages
2011-02-09 20:40:44mgrazebrookcreate