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

Discussion in 'Python' started by castironpi@gmail.com, Apr 21, 2008.

  1. Guest

    What if I say

    oath= yield

    or

    other= yield

    ?

    Does yield evaluate without parenthes? (Eth.)
     
    , Apr 21, 2008
    #1
    1. Advertising

  2. Re: yield expression programmized-formal interpretation.(interpretation of yield expression.)

    En Mon, 21 Apr 2008 15:03:05 -0300, <> 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
     
    Gabriel Genellina, Apr 22, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wallclimber
    Replies:
    3
    Views:
    545
    Wallclimber
    May 26, 2004
  2. Thomas Thorsen
    Replies:
    2
    Views:
    5,324
    Thomas Thorsen
    Mar 18, 2006
  3. tomer
    Replies:
    0
    Views:
    2,027
    tomer
    Jul 28, 2011
  4. Markus
    Replies:
    1
    Views:
    201
    Mark Hubbart
    Sep 27, 2004
  5. Michael Edgar
    Replies:
    13
    Views:
    281
    Brian Candler
    Apr 21, 2011
Loading...

Share This Page