Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > generator function

Reply
Thread Tools

generator function

 
 
chansky
Guest
Posts: n/a
 
      08-07-2003
I read the following link about generator:
http://www.python.org/peps/pep-0255.html
but I am still not so clear on the use/purpose of a generator function
other than the fact that a generator can retain the state of the local
variables within the fuction body. Can someone out there shed some
lights on this topic or share about how/when you would ever use a
generator function.
 
Reply With Quote
 
 
 
 
Skip Montanaro
Guest
Posts: n/a
 
      08-07-2003
>>>>> "tom" == tom chansky <(E-Mail Removed)> writes:

tom> I read the following link about generator:
tom> http://www.python.org/peps/pep-0255.html
tom> but I am still not so clear on the use/purpose of a generator function
tom> other than the fact that a generator can retain the state of the local
tom> variables within the fuction body.

That's generally a more than sufficient reason. Have a look at the
SpamBayes tokenizer module and the several tokenize* methods and functions
it contains for some fairly elaborate examples:

http://tinyurl.com/jaun

Skip

 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      08-07-2003

"chansky" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> I read the following link about generator:
> http://www.python.org/peps/pep-0255.html
> but I am still not so clear on the use/purpose of a generator

function
> other than the fact that a generator can retain the state of the

local
> variables within the fuction body. Can someone out there shed some
> lights on this topic or share about how/when you would ever use a
> generator function.


Besides the other answers, Lib/test/test_generators.py, at 40K,
contains a tutorial and lots of examples, include some that many would
not readily think of.

TJR


 
Reply With Quote
 
 
 
Reply

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
Generator functions subclass generator? Terry Reedy Python 0 06-18-2009 09:51 PM
Problems with email.Generator.Generator Chris Withers Python 20 09-12-2006 11:13 AM
UART with fractional baudrate generator ? Or fractional baudrate generator alone Martin Maurer VHDL 3 04-19-2006 01:26 PM
subtle side effect of generator/generator expression bonono@gmail.com Python 9 10-16-2005 06:42 PM
generator function within a generator function doesn't execute? TheDustbustr Python 1 07-25-2003 10:45 AM



Advertisments