generator function

Discussion in 'Python' started by chansky, Aug 7, 2003.

  1. chansky

    chansky Guest

    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.
     
    chansky, Aug 7, 2003
    #1
    1. Advertising

  2. >>>>> "tom" == tom chansky <> 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
     
    Skip Montanaro, Aug 7, 2003
    #2
    1. Advertising

  3. chansky

    Terry Reedy Guest

    "chansky" <> wrote in message
    news:...
    > 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
     
    Terry Reedy, Aug 7, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Maurer
    Replies:
    3
    Views:
    5,013
    Peter
    Apr 19, 2006
  2. TheDustbustr
    Replies:
    1
    Views:
    483
    Sami Hangaslammi
    Jul 25, 2003
  3. Replies:
    9
    Views:
    575
  4. Chris Withers

    Problems with email.Generator.Generator

    Chris Withers, Sep 11, 2006, in forum: Python
    Replies:
    20
    Views:
    1,745
    Max M
    Sep 12, 2006
  5. weafon
    Replies:
    1
    Views:
    333
    Diez B. Roggisch
    Jul 14, 2009
Loading...

Share This Page