[Tutor] PyCountry currency formatting woes

Sithembewena Lloyd Dube zebra05 at gmail.com
Sun May 4 22:25:05 CEST 2014


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140504/f9a08102/attachment.html>


More information about the Tutor mailing list