Generator naming convention?

Diez B. Roggisch deets at nospam.web.de
Wed Jun 28 22:10:47 CEST 2006


aurora00 at gmail.com schrieb:
> I use generators a lot. E.g.
> 
> 
> def gen_words(text)
>   ... parse text ...
>   yield each word in text
> 
> for word in gen_words(text):
>   print word
> 
> 
> I don't like the name gen_xxx() very much. Looking for some inspiration
> to name generators. Here are some of my ideas:
> 
>   enumerate_words
>   gen_words
>   generate_words
>   parse_words
>   walk_words
> 
> Any idea? Do you have a naming convention for generators?

No. From my POV, a generator is not different from any other method 
returning a list. I don't care if the implementation is

def words():
    return ["dies", "ist", "das", "Haus", "vom", "Nikolaus"]

or

def words():
    for w in ["dies", "ist", "das", "Haus", "vom", "Nikolaus"]:
        yield w


Regards,

Diez



More information about the Python-list mailing list