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

View File

@ -287,6 +287,17 @@ def pluralize(i, s):
return s + 's' return s + 's'
def nItems(n, item, between=None): 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: if between is None:
return '%s %s' % (n, pluralize(n, item)) return '%s %s' % (n, pluralize(n, item))
else: else:
@ -386,4 +397,8 @@ class IterableMap(object):
return False return False
if __name__ == '__main__':
import sys, doctest
doctest.testmod(sys.modules['__main__'])
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: