mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 04:02:46 +01:00
Added a docstring and doctested nItems.
This commit is contained in:
parent
18a8725905
commit
325e751149
15
src/utils.py
15
src/utils.py
@ -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:
|
||||||
|
Loading…
Reference in New Issue
Block a user