Thank you all, babel works just fine. I also tried ccy, which isn't bad either - except that it returns non-unicode currency letters for countries in the Eurozone.
On Mon, May 5, 2014 at 10:10 AM, Peter Otten <__pete...@web.de> wrote: > Sithembewena Lloyd Dube wrote: > > > 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? > > It looks like the development version of babel > > > http://babel.pocoo.org/docs/api/numbers/#babel.numbers.get_territory_currencies > > can do what you want: > > $ LANG=en_US.UTF-8 python > Python 2.7.5+ (default, Feb 27 2014, 19:37:08) > [GCC 4.8.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import babel.numbers as bn > >>> bn.get_territory_currencies("DE") > ['EUR'] > >>> print bn.format_currency(1.234, "EUR") > €1.23 > >>> print bn.format_currency(1.234, "EUR", locale="DE") > 1,23 € > >>> import babel > >>> babel.__version__ > '2.0-dev' > > _______________________________________________ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- 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 django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. 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-SnCDmUJPseY7q27xifgkaKJou5Xbvo5_OWf-DFBsrP85m0A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.