Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_currency_code(name):
""" Retrieve a currency code by the currency name """
try:
return pycountry.currencies.lookup(name).alpha_3
except LookupError:
return None
def get_currency_name(code):
""" get the name of a currency from its code """
try:
cur = pycountry.currencies.lookup(code)
return '{code} - {name}'.format(code=cur.alpha_3, name=cur.name)
except LookupError:
return code # return what was passed in if not found