Calling coroutine from coroutine in python -
i came across issue today , i'm not quite why works this:
def outside(): print 'before' inside() print 'after' yield 'world' def inside(): print 'inside' yield 'hello' n in outside(): print n
(naive) expectation of output:
before inside hello after world
actual output:
before after world
is not possible call coroutine inside coroutine? articles read on coroutines , yield didn't elaborate on issue , i'm quite lost here. shed light on behaviour please? in advance!
it totally possible. when call inside()
creates coroutine. in order yield result, need initialize coroutine , yield follows:
def outside(): print 'before' in inside(): yield print 'after' yield 'world'
and result expected:
before inside hello after world
Comments
Post a Comment