Thanks, i was actually getting the error information to update the post.
Apoligies to waste your time posting here - I could not find an appropriate
PyCountry discussion list and my next best bet seemed to be a Python users'
list.

For those who care to look, the error is as follows (a concise example from
an interactive shell:

import pycountry
country = pycountry.countries.get(alpha2='DE')
currency = pycountry.currencies.get(numeric=country.numeric)
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/pymodules/python2.6/pycountry/db.py", line 83, in get
return self.indices[field][value]
KeyError: '276'

The obvious issue here is that the pycountry.countries collection does not
contain a currency with a numeric of 276 (Germany's numeric) - yet it does
contain the Euro. Any ideas as to what the way around this may be?


On Sun, May 4, 2014 at 10:25 PM, Sithembewena Lloyd Dube
<[email protected]>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
>



-- 
Regards,
Sithu Lloyd Dube

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAH-SnCD%2BY24XvE796wyqNXYaXhT8djSE%3DhHXmYaXJmSpZ%2BwDkQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to