Re: Iteratoration question

2009-04-03 Thread Diez B. Roggisch
while what you are doing is interesting, it is not the same as Python's iterators, which use yield from a function and don't require storing a value in a class. look for yield in the python docs. this comment may be irrelevant; i am just worried you are confusing the above (which apart from

Re: Iteratoration question

2009-04-03 Thread Steven D'Aprano
On Thu, 02 Apr 2009 18:07:38 -0700, grocery_stocker wrote: Okay, I was thinking more about this. I think this is also what is irking me. Say I have the following.. a = [1,2,3,4] for x in a: ... print x ... 1 2 3 4 Would 'a' somehow call __iter__ and next()? If so, does python

Iteratoration question

2009-04-02 Thread grocery_stocker
Give the following code.. class it: ...def __init__(self): ...self.count = -1 ...def next(self): ...self.count +=1 ...if self.count 4: ...return self.count ...else: ...raise StopIteration ... def some_func(): ... return it()

Re: Iteratoration question

2009-04-02 Thread andrew cooke
grocery_stocker wrote: Give the following code.. class it: ...def __init__(self): ...self.count = -1 ...def next(self): ...self.count +=1 ...if self.count 4: ...return self.count ...else: ...raise StopIteration ... def

Re: Iteratoration question

2009-04-02 Thread Rhodri James
On Thu, 02 Apr 2009 23:14:49 +0100, grocery_stocker cdal...@gmail.com wrote: Give the following code.. class it: ...def __init__(self): ...self.count = -1 ...def next(self): ...self.count +=1 ...if self.count 4: ...return self.count ...

Re: Iteratoration question

2009-04-02 Thread grocery_stocker
in summary: iterator is bound to one instance of it, while some_func() returns a new instance each time it is called. BUT while what you are doing is interesting, it is not the same as Python's iterators, which use yield from a function and don't require storing a value in a class. look

Re: Iteratoration question

2009-04-02 Thread Rhodri James
On Thu, 02 Apr 2009 23:37:16 +0100, grocery_stocker cdal...@gmail.com wrote: in summary: iterator is bound to one instance of it, while some_func() returns a new instance each time it is called. BUT while what you are doing is interesting, it is not the same as Python's iterators, which

Re: Iteratoration question

2009-04-02 Thread andrew cooke
grocery_stocker wrote: in summary: iterator is bound to one instance of it, while some_func() returns a new instance each time it is called. BUT while what you are doing is interesting, it is not the same as Python's iterators, which use yield from a function and don't require storing a

Re: Iteratoration question

2009-04-02 Thread Robert Kern
On 2009-04-02 18:08, andrew cooke wrote: grocery_stocker wrote: in summary: iterator is bound to one instance of it, while some_func() returns a new instance each time it is called. BUT while what you are doing is interesting, it is not the same as Python's iterators, which use yield from a

Re: Iteratoration question

2009-04-02 Thread andrew cooke
Robert Kern wrote: replace return with yield and it might work. i have to go eat, but if it doesn't read the python docs on iterators - for example http://docs.python.org/reference/expressions.html#index-1825 No, .next() needs to be a regular function that returns a value. What he needs is

Re: Iteratoration question

2009-04-02 Thread grocery_stocker
On Apr 2, 4:41 pm, andrew cooke and...@acooke.org wrote: Robert Kern wrote: replace return with yield and it might work. i have to go eat, but if it doesn't read the python docs on iterators - for examplehttp://docs.python.org/reference/expressions.html#index-1825 No, .next() needs to

Re: Iteratoration question

2009-04-02 Thread andrew cooke
grocery_stocker wrote: Okay, I was thinking more about this. I think this is also what is irking me. Say I have the following.. a = [1,2,3,4] for x in a: ... print x ... 1 2 3 4 Would 'a' somehow call __iter__ and next()? If so, does python just perform this magically? yes! in

Re: Iteratoration question

2009-04-02 Thread andrew cooke
grocery_stocker wrote: Okay, I was thinking more about this. I think this is also what is irking me. Say I have the following.. a = [1,2,3,4] for x in a: ... print x ... 1 2 3 4 Would 'a' somehow call __iter__ and next()? If so, does python just perform this magically? and the

Re: Iteratoration question

2009-04-02 Thread Rhodri James
On Fri, 03 Apr 2009 02:07:38 +0100, grocery_stocker cdal...@gmail.com wrote: Okay, I was thinking more about this. I think this is also what is irking me. Say I have the following.. a = [1,2,3,4] for x in a: ... print x ... 1 2 3 4 Would 'a' somehow call __iter__ and next()? If so,

Re: Iteratoration question

2009-04-02 Thread andrew cooke
Rhodri James wrote: On Fri, 03 Apr 2009 02:07:38 +0100, grocery_stocker cdal...@gmail.com wrote: Would 'a' somehow call __iter__ and next()? If so, does python just perform this magically? No. It's for that invokes the iteration protocol; that's pretty much the definition of it. You have

Re: Iteratoration question

2009-04-02 Thread MRAB
grocery_stocker wrote: On Apr 2, 4:41 pm, andrew cooke and...@acooke.org wrote: Robert Kern wrote: replace return with yield and it might work. i have to go eat, but if it doesn't read the python docs on iterators - for examplehttp://docs.python.org/reference/expressions.html#index-1825 No,

Re: Iteratoration question

2009-04-02 Thread grocery_stocker
On Apr 2, 6:33 pm, Rhodri James rho...@wildebst.demon.co.uk wrote: On Fri, 03 Apr 2009 02:07:38 +0100, grocery_stocker cdal...@gmail.com wrote: Okay, I was thinking more about this. I think this is also what is irking me. Say I have the following.. a = [1,2,3,4] for x in a: ...