***locale.Error: unsupported locale setting***

Vlastimil Brom vlastimil.brom at gmail.com
Thu Dec 9 18:52:15 EST 2010


2010/12/9 Anurag Chourasia <anurag.chourasia at gmail.com>:
> Hi All,
> When i try to set a locale manually, i get this error.
>>>> import locale
>>>> locale.setlocale(locale.LC_ALL, 'es_cl.iso88591')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/local/lib/python2.7/locale.py", line 531, in setlocale
>     return _setlocale(category, locale)
> locale.Error: unsupported locale setting
> On my OS, when i run the locale -a command, i get this output
> -------------------------
> locale -a
> C
> POSIX
> en_US
> en_US.8859-15
> en_US.ISO8859-1
> -------------------------
> Does this means that on my machine, Python will be able to make use of above
> listed locales?
> If yes then how can i possibly use the locale.setformat (or anything else
> for that matter) to group numbers using '.' as the thousands separator?
> If i use the locale en_US then ',' is the thousands separator.
>>>> import locale
>>>> locale.setlocale(locale.LC_ALL, 'en_US')
> 'en_US'
>>>> locale.format("%d", 1255000, grouping=True)
> '1,255,000'
> Regards,
> Anurag
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
Hi,
I am not sure, it helps in your case, but the simple locale aliases
(like "Spanish") seem to work for me (py 2.7.1, win 7)

>>> locale.getlocale()
('Czech_Czech Republic', '1250')
>>> locale.localeconv()['thousands_sep']
'\xa0'
>>> locale.setlocale(locale.LC_ALL, "Spanish")
'Spanish_Spain.1252'
>>> locale.localeconv()['thousands_sep']
'.'
>>> locale.format("%d", 1255000, grouping=True)
'1.255.000'
>>>

hth,
  vbr



More information about the Python-list mailing list