Added a docstring and doctested nItems.

This commit is contained in:
Jeremy Fincher 2003-10-04 13:04:01 +00:00
parent 18a8725905
commit 325e751149
1 changed files with 15 additions and 0 deletions

View File

@ -287,6 +287,17 @@ def pluralize(i, s):
return s + 's'
def nItems(n, item, between=None):
"""Works like this:
>>> nItems(1, 'clock')
'1 clock'
>>> nItems(10, 'clock')
'10 clocks'
>>> nItems(10, 'clock', between='grandfather')
'10 grandfather clocks'
"""
if between is None:
return '%s %s' % (n, pluralize(n, item))
else:
@ -386,4 +397,8 @@ class IterableMap(object):
return False
if __name__ == '__main__':
import sys, doctest
doctest.testmod(sys.modules['__main__'])
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: