Naming conventions for iterator methods?

John J. Lee jjl at pobox.com
Mon Dec 22 18:58:13 EST 2003


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 particular case: I have a class that can be iterated over in
several ways, so I need to have a method other than __iter__ to return
iterators.

http://wwwsearch.sf.net/bits/pullparser.py


The class pullparser.PullParser can iterate over HTML tokens (which
includes tags, comments, declarations, etc.) or just over the tokens
representing tags, skipping all other tokens.  So __iter__ returns an
iterator over tokens, and tag_iter() over tags.  Then I wondered if I
should be following a standard naming convention.  There's a method
.get_tag(), so I guess the should be related to that in some obvious
way.


John




More information about the Python-list mailing list