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 nex
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 Apr 2, 6:33 pm, "Rhodri James" wrote:
> On Fri, 03 Apr 2009 02:07:38 +0100, 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
>
grocery_stocker wrote:
On Apr 2, 4:41 pm, "andrew cooke" 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
Rhodri James wrote:
> On Fri, 03 Apr 2009 02:07:38 +0100, grocery_stocker
> 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 read th
On Fri, 03 Apr 2009 02:07:38 +0100, 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
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 th
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 th
On Apr 2, 4:41 pm, "andrew cooke" 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 be
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
>
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
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
On Thu, 02 Apr 2009 23:37:16 +0100, 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
>
> 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
On Thu, 02 Apr 2009 23:14:49 +0100, 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:
...
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 StopIterati
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
17 matches
Mail list logo