I believe I understand now. the yield keyword is sort of like a cousin
to return. return will bring back an object I can work with and so does
yield *but* yield's object will most likely support the .next() method.
So, if I worked with a function that ends with the return keyword and
it returns a
vbgunz wrote:
I believe I understand now. the yield keyword is sort of like a cousin
to return. return will bring back an object I can work with and so does
yield *but* yield's object will most likely support the .next() method.
No, that's not really how it works. When a generator function is
Robert Kern wrote:
vbgunz wrote:
I believe I understand now. the yield keyword is sort of like a cousin
to return. return will bring back an object I can work with and so does
yield *but* yield's object will most likely support the .next() method.
No, that's not really how it works. When a
OK. I hope my understanding of the yield keyword and generators in a
general sense are now better understood. When a generator function is
assigned to an identifier, no code is executed and a generator is
immediately returned. When the next() method is called on the new
generator, code from top to
vbgunz wrote:
OK. I hope my understanding of the yield keyword and generators in a
general sense are now better understood. When a generator function is
assigned to an identifier, no code is executed and a generator is
immediately returned. When the next() method is called on the new
I am afraid that this is the first time in which I would probably need
something explained to me as if I were a little child. I am having a
hard time getting this through my thick skull. What in the world is
wrong with this!?
''' ### '''
Em Qui, 2006-03-16 às 16:17 -0800, vbgunz escreveu:
print generatorFunction() # generator object at 0xb723022c
print generatorFunction().next()# item1
print generatorFunction().next()# item1
print generatorFunction().next()# item1
Each time you say generatorFunction(),
vbgunz wrote:
def generatorFunction(sequence=['item1', 'item2', 'item3']):
for item in sequence:
yield item
yieldedValue = generatorFunction()
You're creating an iterator here and binding it to name yieldedValue
(which is bogus, it should be named valueGenerator or sth like
vbgunz wrote:
I am afraid that this is the first time in which I would probably need
something explained to me as if I were a little child. I am having a
hard time getting this through my thick skull. What in the world is
wrong with this!?
'''
it's easy to explain
class X:
pass
x=X()
y=X()
x and y are different instances
one can put in x
x.item = 1
y doesn't even have an attribute item for example
similar with generators
they are *different* objects of same kind generator
def fib():
... a,b = 1,1
... while True:
vbgunz wrote:
I am afraid that this is the first time in which I would probably need
something explained to me as if I were a little child. I am having a
hard time getting this through my thick skull. What in the world is
wrong with this!?
'''
vbgunz wrote:
I am afraid that this is the first time in which I would probably need
something explained to me as if I were a little child. I am having a
hard time getting this through my thick skull. What in the world is
wrong with this!?
'''
12 matches
Mail list logo