470,613 Members | 1,787 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,613 developers. It's quick & easy.

yield expression programmized-formal interpretation. (interpretationof yield expression.)

What if I say

oath= yield

or

other= yield

?

Does yield evaluate without parenthes? (Eth.)
Jun 27 '08 #1
1 989
En Mon, 21 Apr 2008 15:03:05 -0300, <ca********@gmail.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.htmland the grammar definition at
<http://docs.python.org/ref/grammar.txtyou 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:

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

Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by hq4ever (at) 012 (dot) net (dot) il | last post: by
23 posts views Thread by Paul Rubin | last post: by
44 posts views Thread by Steven T. Hatton | last post: by
14 posts views Thread by John Temples | last post: by
3 posts views Thread by andy.leszczynski | last post: by
22 posts views Thread by Mateuszk87 | last post: by
28 posts views Thread by Marc Gravell | last post: by
3 posts views Thread by Ehsan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.