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

Discussion in 'Python' started by Vlastimil Brom, Dec 9, 2010.

  1. 2010/12/9 Anurag Chourasia <>:
    > 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
     
    Vlastimil Brom, Dec 9, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maurice Hulsman
    Replies:
    1
    Views:
    1,898
    Guus Bosman
    Jul 25, 2004
  2. robert
    Replies:
    3
    Views:
    389
    Leo Kislov
    Nov 6, 2006
  3. Replies:
    4
    Views:
    1,033
  4. Gabriel Genellina
    Replies:
    0
    Views:
    728
    Gabriel Genellina
    Feb 18, 2009
  5. Sibylle Koczian
    Replies:
    2
    Views:
    1,148
    Sibylle Koczian
    Nov 20, 2010
Loading...

Share This Page