On 04/05/2014 21:25, Sithembewena Lloyd Dube wrote:
Hi everyone,
I have a function which accepts an alpha2 country code and a price
string, where the aim is to get the country's currency and use the
currency.letter property of that currency to format the supplied price
string.
The above works fine so far - yet it falls over when called with Germany
as the country as follows:
currency = pycountry.currencies.get(numeric=country.numeric)
The function implementation is as follows:
def formatPrice(self, alpha2CountryCode, price):
"""
@param alpha2CountryCode: The 2-character country code for
which to format the price value
@param price: The price value as a string
@return: A string representing the formatted monetary value for
this country for this price.
#Get country by alpha2 code
country = pc.countries.get(alpha2=alpha2CountryCode.upper())
#Get currency by country's numeric and format price
currency = pc.currencies.get(numeric=country.numeric)
letter = currency.letter
formattedCurrency = "%s %s" % (letter, price)
return formattedCurrency
Any ideas as to what the issue may be?
Thanks :)
--
Regards,
Sithu Lloyd Dube
Sorry but this list is aimed at people learning the core Python
language, not a third party module, which I've never heard of
incidentally. You might get lucky if some regular here has used the
package, but even then "it falls over" isn't too helpful.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
---
This email is free from viruses and malware because avast! Antivirus protection
is active.
http://www.avast.com
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor