Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39833
| X-Received | by 10.224.189.78 with SMTP id dd14mr7340498qab.0.1361752769583; Sun, 24 Feb 2013 16:39:29 -0800 (PST) |
|---|---|
| X-Received | by 10.49.106.131 with SMTP id gu3mr96402qeb.36.1361752769436; Sun, 24 Feb 2013 16:39:29 -0800 (PST) |
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!dd2no2760187qab.0!news-out.google.com!t2ni671qaj.0!nntp.google.com!dd2no2760181qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Sun, 24 Feb 2013 16:39:29 -0800 (PST) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=118.135.59.137; posting-account=EUV6tAoAAAA_IfJF_x-XYQxCI2bc4CDF |
| NNTP-Posting-Host | 118.135.59.137 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <eb6313dd-94f9-406d-b353-3d64d171e0a7@googlegroups.com> (permalink) |
| Subject | yield expression |
| From | Ziliang Chen <zlchen.ken@gmail.com> |
| Injection-Date | Mon, 25 Feb 2013 00:39:29 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Lines | 19 |
| X-Received-Bytes | 1723 |
| Xref | csiph.com comp.lang.python:39833 |
Show key headers only | View raw
Hi folks,
When I am trying to understand "yield" expression in Python2.6, I did the following coding. I have difficulty understanding why "val" will be "None" ? What's happening under the hood? It seems to me very time the counter resumes to execute, it will assign "count" to "val", so "val" should NOT be "None" all the time.
Thanks !
code snippet:
----
def counter(start_at=0):
count = start_at
while True:
val = (yield count)
if val is not None:
count = val
else:
print 'val is None'
count += 1
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
yield expression Ziliang Chen <zlchen.ken@gmail.com> - 2013-02-24 16:39 -0800
Re: yield expression Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-25 00:51 +0000
Re: yield expression Ziliang Chen <zlchen.ken@gmail.com> - 2013-02-24 16:59 -0800
Re: yield expression Ziliang Chen <zlchen.ken@gmail.com> - 2013-02-24 16:59 -0800
csiph-web