The issue is that nn() does not return an iterable object. _nn()
returns an iterable object but nothing is done with it. Either of the
following should work though:
def nn():
def _nn():
print 'inside'
yield 1
print 'before'
for i in _nn():
yield i
print 'aft
wrote in news:[EMAIL PROTECTED] in
comp.lang.python:
> Any insight?
>From the docs:
The yield statement is only used when defining a generator function, and is
only used in the body of the generator function. Using a yield statement in
a function definition is sufficient to cause that defin
[EMAIL PROTECTED] wrote:
> Hi,
>
> I might understand why this does not work, but I am not convinced it
> should not - following:
>
> def nnn():
> print 'inside'
> yield 1
>
> def nn():
> def _nn():
> print 'inside'
> yield 1
>
> print 'before'
> _nn()
>
Hi,
I might understand why this does not work, but I am not convinced it
should not - following:
def nnn():
print 'inside'
yield 1
def nn():
def _nn():
print 'inside'
yield 1
print 'before'
_nn()
print 'after'
for i in nnn():
print i
for i in nn():