Message128238
| 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:45 | mgrazebrook | set | recipients:
+ mgrazebrook, docs@python |
| 2011年02月09日 20:40:45 | mgrazebrook | set | messageid: <1297284045.4.0.795458647498.issue11163@psf.upfronthosting.co.za> |
| 2011年02月09日 20:40:44 | mgrazebrook | link | issue11163 messages |
| 2011年02月09日 20:40:44 | mgrazebrook | create |
|