PEP 276 -- What else could iter(5) mean?
Gonçalo Rodrigues
op73418 at mail.telepac.pt
Sat Mar 2 22:13:52 EST 2002
On Sun, 03 Mar 2002 02:09:50 +0000, Gonçalo Rodrigues
<op73418 at mail.telepac.pt> wrote:
>On Sat, 02 Mar 2002 17:47:00 -0800, David Eppstein
><eppstein at ics.uci.edu> wrote:
>
>>Here's another way of looking at the same question.
>>An iterable object has a next() function, that's what it means to be
>>iterable. If numbers are iterable, we can call number.next(), right?
>>So what should 5.next() be? Surely anyone familiar with the Peano axioms
>>would say 6, not 0!
>
>Let me add the following example on my post:
>
>>>> class Bogus:
>... def __init__(self, n):
>... self.n = n
>... def __iter__(self):
>... return range(n)
>...
>>>> a = Bogus(10)
>>>> a.next()
>Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
>AttributeError: Bogus instance has no attribute 'next'
>>>>
As you have probably noticed there is an EGREGIOUS error in the above.
My apologies for it (Is past 3 a.m. ...). It should go as
>>> class Bogus:
... def __init__(self, n):
... self.n = n
... def __iter__(self):
... return range(self.n)
...
>>> a = Bogus(6)
>>> a.next()
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
AttributeError: Bogus instance has no attribute 'next'
>>>
More information about the Python-list
mailing list