How do you refer to an iterator in docs?

Jon Clements joncle at googlemail.com
Thu Apr 19 15:08:13 EDT 2012


On Thursday, 19 April 2012 13:21:20 UTC+1, Roy Smith  wrote:
> Let's say I have a function which takes a list of words.  I might write 
> the docstring for it something like:
> 
> def foo(words):
>    "Foo-ify words (which must be a list)"
> 
> What if I want words to be the more general case of something you can 
> iterate over?  How do people talk about that in docstrings?  Do you say 
> "something which can be iterated over to yield words", "an iterable over 
> words", or what?
> 
> I can think of lots of ways to describe the concept, but most of them 
> seem rather verbose and awkward compared to "a list of words", "a 
> dictionary whose keys are words", etc.

I would just write the function signature as (very similar to how itertools does it):

def func(iterable, ..):
  pass

IMHO that documents itself.

If you need explicit, look at the itertools documentation.

hth

Jon.




More information about the Python-list mailing list