Package pytils :: Module numeral
[hide private]
[frames] | no frames]

Module numeral

source code

Plural forms and in-word representation for numerals.

Functions [hide private]
str _get_float_remainder(fvalue, signs=9)
Get remainder of float, i.e.
unicode choose_plural(amount, variants)
Choose proper case depending on amount
unicode rubles(amount, zero_for_kopeck=False)
Get string for money
unicode in_words_int(amount, gender=1)
Integer in words
unicode in_words_float(amount, _gender=2)
Float in words

unicode

raise TypeError: when amount not int or float raise ValueError: when amount is negative raise TypeError: when gender is not int (and not None) raise ValueError: if gender isn't in (1,2,3)
in_words(amount, gender=None)
Numeral in words
unicode sum_string(amount, gender, items=None)
Get sum in words
tuple _sum_string_fn(into, tmp_val, gender, items=None)
Make in-words representation of single order

Variables [hide private]
  __revision__ = '$Id: numeral.py 29 2006-10-21 08:28:27Z the.pythy $'
  __id__ = '$Id: numeral.py 29 2006-10-21 08:28:27Z the.pythy $'
  __url__ = '$URL: https://pythy.googlecode.com/svn/trunk/pytils...
  FRACTIONS = ((u'\u0434\u0435\u0441\u044f\u0442\u0430\u044f', u'\...
Forms (1, 2, 5) for fractions
  ONES = {0: (u'', u'', u''), 1: (u'\u043e\u0434\u0438\u043d'...
Forms (1, 2, 5) for ones
  TENS = {0: u'', 2: u'\u0434\u0432\u0430\u0434\u0446\u0430\u...
Tens
  HUNDREDS = {0: u'', 1: u'\u0441\u0442\u043e', 2: u'\u0434\u0432...
Hundreds

Function Details [hide private]

_get_float_remainder(fvalue, signs=9)

source code 
Get remainder of float, i.e. 2.05 -> '05'
Parameters:
  • fvalue (int or float) - input value
  • signs (int) - maximum number of signs
Returns: str
remainder
Raises:
  • TypeError - fvalue neither int, no float
  • ValueError - fvalue is negative
  • ValueError - signs overflow

choose_plural(amount, variants)

source code 
Choose proper case depending on amount
Parameters:
  • amount (int) - amount of objects
  • variants (3-element sequence of unicode or unicode (three variants with delimeter ',')) - variants (forms) of object in such form: (1 object, 2 objects, 5 objects).
Returns: unicode
proper variant
Raises:
  • TypeError - amount isn't int, variants isn't sequence
  • ValueError - amount is negative
  • ValueError - variants' length lesser than 3

rubles(amount, zero_for_kopeck=False)

source code 
Get string for money
Parameters:
  • amount (int or float) - amount of money
  • zero_for_kopeck (bool) - If false, then zero kopecks ignored
Returns: unicode
in-words representation of money's amount
Raises:
  • TypeError - amount neither int, no float
  • ValueError - amount is negative

in_words_int(amount, gender=1)

source code 
Integer in words
Parameters:
  • amount (int) - numeral
  • gender (int) - gender (male=1, female=2, neuter=3)
Returns: unicode
in-words reprsentation of numeral
Raises:
  • TypeError - when amount is not int
  • ValueError - amount is negative

in_words_float(amount, _gender=2)

source code 
Float in words
Parameters:
  • amount (float) - float numeral
Returns: unicode
in-words reprsentation of float numeral
Raises:
  • TypeError - when amount is not float
  • ValueError - when ammount is negative

in_words(amount, gender=None)

source code 
Numeral in words
Parameters:
  • amount (int or float) - numeral
  • gender (int) - gender (male=1, female=2, neuter=3)
Returns:

unicode

raise TypeError: when amount not int or float raise ValueError: when amount is negative raise TypeError: when gender is not int (and not None) raise ValueError: if gender isn't in (1,2,3)
in-words reprsentation of numeral

sum_string(amount, gender, items=None)

source code 
Get sum in words
Parameters:
  • amount (int) - amount of objects
  • gender (int) - gender of object (male=1, female=2, neuter=3)
  • items (3-element sequence of unicode or just unicode (three variants with delimeter ',')) - variants of object in three forms: for one object, for two objects and for five objects
Returns: unicode
in-words representation objects' amount
Raises:
  • TypeError - input parameters' check failed
  • ValueError - items isn't 3-element sequence
  • ValueError - amount bigger than 10**11
  • ValueError - amount is negative

_sum_string_fn(into, tmp_val, gender, items=None)

source code 
Make in-words representation of single order
Parameters:
  • into (unicode) - in-words representation of lower orders
  • tmp_val (int) - temporary value without lower orders
  • gender (int) - gender (male=1, female=2, neuter=3)
  • items (3-element sequence of unicode) - variants of objects
Returns: tuple
new into and tmp_val
Raises:
  • TypeError - input parameters' check failed
  • ValueError - tmp_val is negative

Variables Details [hide private]

__revision__

None
Value:
'$Id: numeral.py 29 2006-10-21 08:28:27Z the.pythy $'                  
      

__id__

None
Value:
'$Id: numeral.py 29 2006-10-21 08:28:27Z the.pythy $'                  
      

__url__

None
Value:
'$URL: https://pythy.googlecode.com/svn/trunk/pytils/pytils/numeral.py
 $'                                                                    
      

FRACTIONS

Forms (1, 2, 5) for fractions
Value:
((u'\u0434\u0435\u0441\u044f\u0442\u0430\u044f',
  u'\u0434\u0435\u0441\u044f\u0442\u044b\u0445',
  u'\u0434\u0435\u0441\u044f\u0442\u044b\u0445'),
 (u'\u0441\u043e\u0442\u0430\u044f',
  u'\u0441\u043e\u0442\u044b\u0445',
  u'\u0441\u043e\u0442\u044b\u0445'),
 (u'\u0442\u044b\u0441\u044f\u0447\u043d\u0430\u044f',
  u'\u0442\u044b\u0441\u044f\u0447\u043d\u044b\u0445',
...                                                                    
      

ONES

Forms (1, 2, 5) for ones
Value:
{0: (u'', u'', u''),
 1: (u'\u043e\u0434\u0438\u043d',
     u'\u043e\u0434\u043d\u0430',
     u'\u043e\u0434\u043d\u043e'),
 2: (u'\u0434\u0432\u0430', u'\u0434\u0432\u0435', u'\u0434\u0432\u043
0'),
 3: (u'\u0442\u0440\u0438', u'\u0442\u0440\u0438', u'\u0442\u0440\u043
8'),
...                                                                    
      

TENS

Tens
Value:
{0: u'',
 2: u'\u0434\u0432\u0430\u0434\u0446\u0430\u0442\u044c',
 3: u'\u0442\u0440\u0438\u0434\u0446\u0430\u0442\u044c',
 4: u'\u0441\u043e\u0440\u043e\u043a',
 5: u'\u043f\u044f\u0442\u044c\u0434\u0435\u0441\u044f\u0442',
 6: u'\u0448\u0435\u0441\u0442\u044c\u0434\u0435\u0441\u044f\u0442',
 7: u'\u0441\u0435\u043c\u044c\u0434\u0435\u0441\u044f\u0442',
 8: u'\u0432\u043e\u0441\u0435\u043c\u044c\u0434\u0435\u0441\u044f\u04
...                                                                    
      

HUNDREDS

Hundreds
Value:
{0: u'',
 1: u'\u0441\u0442\u043e',
 2: u'\u0434\u0432\u0435\u0441\u0442\u0438',
 3: u'\u0442\u0440\u0438\u0441\u0442\u0430',
 4: u'\u0447\u0435\u0442\u044b\u0440\u0435\u0441\u0442\u0430',
 5: u'\u043f\u044f\u0442\u044c\u0441\u043e\u0442',
 6: u'\u0448\u0435\u0441\u0442\u044c\u0441\u043e\u0442',
 7: u'\u0441\u0435\u043c\u044c\u0441\u043e\u0442',
...