Python 3.0a: investigating changes
So I'm in a Portland coffee shop, iTunes on the speakers, daughter reading a novel. I remember Guido saying something about 'next' changing a little. What I'm finding tonight is the old some_generator.next() syntax is breaking (by design I assume), while next(some_generator) works great. What's getting triggered under the hood is __next__, which of course you can trigger directly.
thegen = (i for i in range(10)) thegen <generator object at 0xb7c9430c> type(thegen) <type 'generator'> thegen.next() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'generator' object has no attribute 'next' dir(thegen) ['__class__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__lt__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'close', 'gi_frame', 'gi_running', 'send', 'throw'] next(thegen) 0 next(thegen) 1 next(thegen) 2 def fibbo(a=0,b=1): ... while True: ... yield a ... a,b = a+b, a ... somegen = fibbo() type(somegen) <type 'generator'> type.next() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: type object 'type' has no attribute 'next' next(somegen) 0 next(somegen) 1 next(somegen) 1 somegen.__next__() 2 somegen.__next__() 3 somegen.__next__() 5 somegen.__next__() 8 somegen.__next__() 13 somegen.__next__() 21
and so on. Kirby
participants (1)
-
kirby urner