New submission from Michael Grazebrook :
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(10))
for n in iter( square_generator.next, 144):
print n
--
assignee: docs@python
components: Documentation
messages: 128238
nosy: docs@python, mgrazebrook
priority: normal
severity: normal
status: open
title: iter() documentation code doesn't work
type: behavior
versions: Python 2.6
___
Python tracker
<http://bugs.python.org/issue11163>
___
___
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com