En Mon, 21 Apr 2008 15:03:05 -0300, <ca********@gma il.comescribió:
What if I say
oath= yield
or
other= yield
?
Does yield evaluate without parenthes? (Eth.)
You can't use yield except in a generator function. From
<http://docs.python.org/ref/yieldexpr.htmla nd the grammar definition at
<http://docs.python.org/ref/grammar.txtyou can see that
assignment_stmt ::=
(target_list "=")+
(expression_lis t | yield_expressio n)
yield_expressio n ::= "yield" [expression_list]
The last expression_list is optional so a bare yield should be allowed in
the right hand side of an assignment, as if it were `yield None` (I think
such behavior is specified in the original PEP). Let's try:
pydef gen():
.... x = yield
.... y = yield "second"
.... yield x, y
....
pyg = gen()
pyprint g.next()
None
pyprint g.send(123)
second
pyprint g.send(456)
(123, 456)
pyprint g.send(789)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
--
Gabriel Genellina