string: __iter__()?

Paul Rubin http
Wed Oct 4 12:08:29 CEST 2006

"mrquantum" <mrquantum at> writes:
> Just for curiosity i'd like to know why strings don't support the
> iteration protocoll!? Is there some deeper reason for this?
> >>> hasattr('SomeString', '__iter__')
> False

It is a little but odd.  But at least in 2.3.4:

    Python 2.3.4 (#1, Feb  2 2005, 12:11:53) 
    [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> a = iter('hi there')
    >>> a
    <iterator object at 0xb7c7f8ec>
    >>> print [x for x in a]
    ['h', 'i', ' ', 't', 'h', 'e', 'r', 'e']

So it looks like the iter is still there, but comes from some older
layer of the implementation.  

More information about the Python-list mailing list