En Mon, 21 Apr 2008 15:03:05 -0300, <[EMAIL PROTECTED]> escribió:

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.html> and the grammar definition at <http://docs.python.org/ref/grammar.txt> you can see that

assignment_stmt ::=
             (target_list "=")+
              (expression_list | yield_expression)

yield_expression ::= "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:

py> def gen():
...   x = yield
...   y = yield "second"
...   yield x, y
...
py> g = gen()
py> print g.next()
None
py> print g.send(123)
second
py> print g.send(456)
(123, 456)
py> print g.send(789)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to