I'm familiar with yield to return a value thanks mostly to this question
but what does yield do when it is on the right side of an assignment?
@coroutine
def protocol(target=None):
while True:
c = (yield)
def coroutine(func):
def start(*args,**kwargs):
cr = func(*args,**kwargs)
cr.next()
return cr
return start
I came across this, on the code samples of this blog, while researching state machines and coroutines.
send()
on a generator, you have to callnext()
to actually start it, or you'll get a TypeError saying:TypeError: can't send non-None value to a just-started generator
– Imperialism