473,785 Members | 2,938 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

What if I say

oath= yield

or

other= yield

?

Does yield evaluate without parenthes? (Eth.)
Jun 27 '08 #1
1 1077
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

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
1915
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
3235
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 there are no assignment expressions in Python, I have to use a temp var. That's a little more messy, but bearable:
13
1878
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 As this:
44
2466
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 semantics"? What, if any, associated semantics are shared by all objects? That part seems to go beyond the FAQ. Does anybody know of a resource that discusses (focuses on) this topic? -- p->m == (*p).m == p.m
14
2081
by: John Temples | last post by:
Given this code: extern volatile unsigned char v; int main(void) { v; return 0; }
3
3523
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
2219
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
16423
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 write a safe but easy implementation (i.e. no codedom) for an IBindingListView.Filter (by compiling to a Predicate<T>). Anybody know if this is possible at all? Marc
3
6937
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 experienced programmers. Visit http://diveintopython.org/ for the latest version.
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10330
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.