You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
615 B
25 lines
615 B
from decimal import Decimal, InvalidOperation
|
|
|
|
def getInt(d, key, default):
|
|
""" Helper for dict.get to return the default on error. """
|
|
try:
|
|
return int(d.get(key, default))
|
|
except ValueError:
|
|
return default
|
|
|
|
def getDecimal(d, key, default):
|
|
""" Helper for dict.get to return the default on error or a Decimal
|
|
with a precision of 2. """
|
|
try:
|
|
return Decimal("%.2f" % float(d.get(key, default)), 2)
|
|
except InvalidOperation:
|
|
return default
|
|
except ValueError:
|
|
return default
|
|
|
|
def getError(err, msg):
|
|
""" Get an error, write a message on it an return it. """
|
|
err.write("\n%s\n" % (msg,))
|
|
return err
|
|
|