473,379 Members | 1,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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 1060
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: hq4ever (at) 012 (dot) net (dot) il | last post by:
function testemail($email) { $validEmailExpr = "^(?)*@(?)*$"; return eregi($validEmailExpr, $email); } $email = "foo@bar.gov.mil"; testmail($email); //return TRUE
23
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since...
13
by: snacktime | last post by:
I need to convert a generator expression to a list expression so it will work under python 2.3. I rewrote this: for c in range(128): even_odd = (sum(bool(c & 1<<b) for b in range(8))) & 1 ...
44
by: Steven T. Hatton | last post by:
This may seem like such a simple question, I should be embarrassed to ask it. The FAQ says an object is "A region of storage with associated semantics." OK, what exactly is meant by "associated...
14
by: John Temples | last post by:
Given this code: extern volatile unsigned char v; int main(void) { v; return 0; }
3
by: andy.leszczynski | last post by:
Hi, I might understand why this does not work, but I am not convinced it should not - following: def nnn(): print 'inside' yield 1 def nn():
22
by: Mateuszk87 | last post by:
Hi. may someone explain "yield" function, please. how does it actually work and when do you use it? thanks in forward mateusz
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
3
by: Ehsan | last post by:
hi coulde any one show me the usage of "yield" keyword specially in this example: """Fibonacci sequences using generators This program is part of "Dive Into Python", a free Python book for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.