Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > yield expression

Thread Tools

yield expression

Ziliang Chen
Posts: n/a
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
print 'val is None'
count += 1
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
yield expression Ziliang Chen Python 7 02-27-2013 02:59 AM
yield expression Ziliang Chen Python 3 02-25-2013 12:59 AM
[ANN] To Yield or Not to Yield: An Inferable Question Michael Edgar Ruby 13 04-21-2011 05:55 PM
yield expression programmized-formal interpretation. (interpretationof yield expression.) Python 1 04-22-2008 01:32 AM
Yield & associations (was Proc / def /yield semantics) Markus Ruby 1 09-27-2004 07:04 PM