Class and Function Reference¶
Akrophonobolos provides a class, Khremata (χρήματα, “money”) and function for manipulating instances of this class.
- flag akrophonobolos.Fmt(value)¶
Flags for use in formatting
- Member Type:
int
Valid values are as follows:
- GREEK = <Fmt.GREEK: 16>¶
- ENGLISH = <Fmt.ENGLISH: 8>¶
- ABBR = <Fmt.ABBR: 4>¶
- DECIMAL = <Fmt.DECIMAL: 2>¶
- FRACTION = <Fmt.FRACTION: 1>¶
Khremata Class¶
This class represents a Greek monetary amount and provides for formatting and mathematical operations.
- class akrophonobolos.Khremata(amt, limit=None)¶
Represents a monetary amount in Greek talents, drakhmas, and obols.
- akrophonobolos.Khremata.__init__(self, amt, limit=None)¶
- Parameters:
amt (str, float, int, fraction.Fraction, Khremata) – Monetary amount
limit (int) – max denominator for fractions
- Raises:
UnparseableMonetaryString – If amt cannot be parsed
The amount can be provided as an integer number or fractional number of obols, another Kremata instance, or as a string. Strings can be in the format “1t 813d 1.5b”, with upper or lower case “t” indicating talents, “d” drachmas, and “o” or “b” obols or as a Greek acrophonical numeral string such as “Τ𐅅ΗΗΗΔ𐅂𐅂𐅂Ι𐅁”.
Amounts are stored internally as a possibly fractional amount of obols. The
limitparameter can be used to set a maximum value of the denominator for fractional values. See fractions.Fraction.limit_denominator.
- akrophonobolos.Khremata.as_greek(self)¶
- Returns:
Monetary amount as Greek acrophonic numerals
- Return type:
str
- akrophonobolos.Khremata.as_phrase(self, decimal=False)¶
- Parameters:
decimal (bool) – Format as decimal if True, otherwise as a fraction
- Returns:
Monetary amount as an English phrase
- Return type:
str
- akrophonobolos.Khremata.as_abbr(self, decimal=False)¶
- Parameters:
decimal (bool) – Format as decimal if True, otherwise as a fraction
- Returns:
Monetary amount as an abbreviation
- Return type:
str
Implemented special methods and operators¶
- akrophonobolos.Khremata.__str__(self)¶
Return str(self).
- akrophonobolos.Khremata.__repr__(self)¶
Return repr(self).
- akrophonobolos.Khremata.__int__(self)¶
- akrophonobolos.Khremata.__float__(self)¶
- akrophonobolos.Khremata.__eq__(self, other)¶
Return self==value.
- akrophonobolos.Khremata.__ne__(self, other)¶
Return self!=value.
- akrophonobolos.Khremata.__lt__(self, other)¶
Return self<value.
- akrophonobolos.Khremata.__le__(self, other)¶
Return self<=value.
- akrophonobolos.Khremata.__gt__(self, other)¶
Return self>value.
- akrophonobolos.Khremata.__ge__(self, other)¶
Return self>=value.
- akrophonobolos.Khremata.__add__(self, other)¶
- akrophonobolos.Khremata.__sub__(self, other)¶
- akrophonobolos.Khremata.__mul__(self, other)¶
- Raises:
UndefinedMonetaryOperation – if multiplying two
akrophonobolos.Khrematainstances
- akrophonobolos.Khremata.__truediv__(self, other)¶
- akrophonobolos.Khremata.__hash__(self)¶
Return hash(self).
Functions¶
- akrophonobolos.valid_greek_amount(amt)¶
Return True if a Greek numeric string.
- Parameters:
amt (str) – Monetary string
- Return type:
bool
Tests whether
amtcan be parsed as a valid Greek acrophonic numeral such as “Τ𐅅ΗΗΗΔ𐅂𐅂𐅂Ι𐅁”.
- akrophonobolos.valid_amount_str(amt)¶
Return true if a valid monetary abbreviation
- Parameters:
amt (str) – Monetary string
- Return type:
bool
Tests whether
amtcan be parsed as a valid Greek monetary abbreviation such as “1t 813d 1.5b”.
- akrophonobolos.parse_amount(amt)¶
Parse an Athenian currency string into obols.
- Parameters:
amt (str) – Monetary string
- Returns:
Amount in obols
- Return type:
fractions.Fraction
- akrophonobolos.format_amount(amt, fmt_flags=Fmt.ABBR | FRACTION)¶
Format monetary amount as a string
- Parameters:
amt (str) – Monetary string
fmt_flags (Fmt) – Flags for formatting options defaults to Fmt.ABBREV | Fmt.FRACTION
- Returns:
A string formatted string representation
- Return type:
str
Amount can be formatted as Greek akrophonic numerals, an English phrase, or an English abbrevation with
Fmt.GREEK,Fmt.ENGLISH, andFmt.ABBRrespectively.Fmt.ENGLISHandFmt.ABBRcan be combined withFmt.FRACTIONto format partial obols as fractions or withFmt.DECIMALto format them as decimal numbers.Fmt.FRACTIONandFmt.DECIMALhave no effect when combined withFmt.GREEK
- akrophonobolos.loan_term(p, i, r=Fraction(1, 30000), roundoff=True)¶
Calculate loan term in days if principal was p and interest i at rate r
- akrophonobolos.interest_rate(p=Khremata (5t [= 180000.0 obols]), d=1, r=Khremata (1d [= 6.0 obols]))¶
Calculate the simple interest rate that, given a principal amount p returns r in d days
- Parameters:
- Return type:
fractions.Fraction
Return value will be a fraction representing the amount of simple interest returned in one day, so that principal * rate * days will be the total amount of interest
Default values return the common rate: 5 tálanta in one day returns 1 drákhma.
- akrophonobolos.interest(p, d, r=Fraction(1, 30000), roundup=True)¶
Calculate interest on principal p for d days at rate r
- Parameters:
i (str, float, int, fraction.Fraction, Khremata) – Amount of interest
d (int) – Number of days over which to calculate interest
r (fractions.Fraction, int, float) – Simple interest rate
roundup (bool) – If True, result is rounded up to nearest quarter obolós. If False, the exact amount is returned
- Return type:
Kremata
- akrophonobolos.principal(i, d, r=Fraction(1, 30000), roundup=True)¶
Calculate the principal if loan returned i interest after d days at rate r
- Parameters:
i (str, float, int, fraction.Fraction, Khremata) – Amount of interest
d (int) – Number of days over which to calculate interest
r (fractions.Fraction, int, float) – Simple interest rate
roundup (bool) – If True, result is rounded up to nearest quarter obolós. If False, the exact amount is returned
- Return type:
Exceptions¶
- exception akrophonobolos.UndefinedMonetaryOperation¶
- exception akrophonobolos.UnparseableMonetaryString¶