Generator naming convention?

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Wed Jun 28 20:20:09 EDT 2006


aurora00 at gmail.com a écrit :
> 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.

Nor do I.

> 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? D

Any of these names have different (somewhat implied) semantic to me. I'd 
expect enunmerate_words to yield (order, word) pairs, parse_words to 
yield tokens, walk_words to traverse a tree of words, etc

As you see, this is much about what it does than what it is. And FWIW, 
do you prefix function names s with fun_ ?

> you have a naming convention for generators?

No.




More information about the Python-list mailing list