Naming conventions for iterator methods?
Peter Otten
__peter__ at web.de
Tue Dec 23 04:07:25 EST 2003
John J. Lee wrote:
> How do people name their iterator methods / functions?
>
> eg. .iter_foo(), .foo_iter(), .iterfoo(), .fooiter(), .foos(), ...?
>
> Of course, dicts have .iterkeys(), .itervalues() and .iteritems(), but
> I don't like having words run together like that.
My personal naming convention is not yet stable, but I currently favour
foos(). I think iterkeys() etc. were only introduced because there already
were methods like keys() returning the corresponding list.
These I now tend to omit and instead make it explicit when I need a list, e.
g.
alltags = list(parser.tags())
and instead of parser.filtertags(pred):
sometags = [t for t in parser.tags() if pred(t)]
When all returned sequences are iterators, a special prefix/suffix seems
pointless and you may wonder how to name the few exceptions:
list_foo(), foo_list(), listfoo(), foolist(), foos(), ...
:-)
Peter
More information about the Python-list
mailing list