Sunday, 8 September 2013

Returnong generators in python

Returnong generators in python

I want to do something analogous to the following:
def normal(start):
term = start
while True:
yield term
term = term + 1
def iterate(start, inc):
if inc == 1:
return normal(start)
else:
term = start
while True:
yield term
term = term + inc
Now this gives the following error.
SyntaxError: 'return' with argument inside generator
How I can return a generator to one function through another? (Note:
Example shown here doesn't require this kind of functionality but it shows
what I need to do)
Thanks in advance.

No comments:

Post a Comment