iterator question

Erik Max Francis max at alcyone.com
Thu Apr 2 18:21:48 EDT 2009


grocery_stocker wrote:
> How come when I call some_func().next(), the counter doesn't get
> incremented?

Because you're creating a new instance each time you call it.  Each new 
instance starts with 0.

> But when I call iterator.next(), it does.

That's because you're iterating over a single object, so successive 
calls to .next give you success iteration values like you intended.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   We must all hang together, or, most assuredly, we will all hang
    separately. -- John Hancock



More information about the Python-list mailing list