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 chris.jerdonek
Recipients chris.jerdonek, docs@python
Date 2012-04-08.10:05:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1333879538.06.0.592518387164.issue14528@psf.upfronthosting.co.za>
In-reply-to
Content
While converting code from Python 2 to Python 3, I came across the "gotcha" that strings implement __iter__ in Python 3 but not in Python 2.

Looking through the documentation, I don't seem to see anything like this mentioned in the library portion of either Python 2 or 3's documentation:

http://docs.python.org/library/stdtypes.html#iterator-types
http://docs.python.org/py3k/library/stdtypes.html#iterator-types

Or in the documentation describing differences between 2 and 3:

http://docs.python.org/release/3.0.1/whatsnew/3.0.html

In fact, the Python 2 and 3 sections on iterator types seem largely the same.  Python 2's documentation even seems a bit misleading in this regard.  At the beginning of this section, it says, "Sequences, described below in more detail, always support the iteration methods [of which __iter__() is the main one]."  And str and unicode are the first two types mentioned in that next section on sequence types.

Here is a blog post I came across about this issue:

http://plope.com/Members/chrism/python_2_vs_python_3_str_iter

I think it would be worth highlighting this issue somewhere in the Python documentation, or at least acknowledging the change (unless I'm simply looking in the wrong place, in which case maybe it should be made more visible).
History
Date User Action Args
2012-04-08 10:05:38chris.jerdoneksetrecipients: + chris.jerdonek, docs@python
2012-04-08 10:05:38chris.jerdoneksetmessageid: <1333879538.06.0.592518387164.issue14528@psf.upfronthosting.co.za>
2012-04-08 10:05:37chris.jerdoneklinkissue14528 messages
2012-04-08 10:05:37chris.jerdonekcreate