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
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
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()
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
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
...
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
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
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
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
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
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
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
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
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,
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
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,
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:
...
17 matches
Mail list logo