PEP 276 -- What else could iter(5) mean?

Gonçalo Rodrigues op73418 at mail.telepac.pt
Sat Mar 2 21:09:50 EST 2002


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'
>>> 



More information about the Python-list mailing list