[Tutor] range as a not-quite-iterator

Amit Saha amitsaha.in at gmail.com
Sun Aug 4 03:27:45 CEST 2013


On Sun, Aug 4, 2013 at 11:14 AM, Jim Mooney <cybervigilante at gmail.com> wrote:
> using py3.3 on win7
>
> I'm reading the Lutz book, and he clearly calls range an iterator in
> the context of Python 3.0, yet when I try
>
> x = range(1,10)
> next(x)
> I get: builtins.TypeError: 'range' object is not an iterator
> And x itself is returned as: range(1, 10)
>
> What am I missing here? Is it an iterator or not?

I think what you are looking for is x.__iter__()

>>> next(x.__iter__())
1

Sorry for the insufficient explanation or background, but I don't
quite recall it myself well enough.



-- 
http://echorand.me


More information about the Tutor mailing list