[issue11163] iter() documentation code doesn't work

Michael Grazebrook report at bugs.python.org
Wed Feb 9 21:40:45 CET 2011


New submission from Michael Grazebrook <michael at grazebrook.com>:

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

----------
assignee: docs at python
components: Documentation
messages: 128238
nosy: docs at python, mgrazebrook
priority: normal
severity: normal
status: open
title: iter() documentation code doesn't work
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11163>
_______________________________________


More information about the Python-bugs-list mailing list