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 r.david.murray
Recipients andersk, eric.araujo, georg.brandl, r.david.murray, ysj.ray
Date 2010-04-12.17:24:02
SpamBayes Score 1.9203355e-08
Marked as misclassified No
Message-id <1271093045.27.0.901934425307.issue8376@psf.upfronthosting.co.za>
In-reply-to
Content
It might be worth mentioning in the tutorial the specific problem the OP points out: that if an object returns itself in __iter__, then that object can have only one iteration state.  And that therefor only an object that is itself a unique iterator (as opposed to a collection wanting to allow iteration) should return itself as __iter__.

Also note that in the example in the tutorial it says "easy to add the behavior", which *in context* is wrong; pedagogically the better thing to do would be to say "it is easy to write a class that implements an iterator".  As Éric said, splitting the text so that returning an iterator from a collection and constructing an iterator class are distinct topics would greatly improve the exposition.

I'm an experienced Python coder, and I've made this mistake myself.  Often it doesn't break because the code only iterates the object once, but it would be better to have the tutorial encourage doing this correctly by providing good examples and explanations.
History
Date User Action Args
2010-04-12 17:24:05r.david.murraysetrecipients: + r.david.murray, georg.brandl, eric.araujo, ysj.ray, andersk
2010-04-12 17:24:05r.david.murraysetmessageid: <1271093045.27.0.901934425307.issue8376@psf.upfronthosting.co.za>
2010-04-12 17:24:03r.david.murraylinkissue8376 messages
2010-04-12 17:24:02r.david.murraycreate