Python Locales under windows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Moof

    Python Locales under windows

    Hi there,
    I'm trying to use some country-specific services provided by python
    under Windows, and I'm coming up with a couple of problems, specifically
    that floats are not being printed correctly when converted to strings
    (they print out as 1,024.36 instead of 1.024,36), and also the contents
    of \w inside a regexp, which I believe is equivalent to string.letters.

    Under linux, I can get around this by setting the locale correctly.
    Under windows, I'm buggered if I can work out how:
    [color=blue][color=green][color=darkred]
    >>> print "%.2f" % 1024.36 # should be '1024,36'[/color][/color][/color]
    1024.36[color=blue][color=green][color=darkred]
    >>> string.letters #should be 54 letters here, including ñÑ[/color][/color][/color]
    'abcdefghijklmn opqrstuvwxyzABC DEFGHIJKLMNOPQR STUVWXYZ'[color=blue][color=green][color=darkred]
    >>> locale.getlocal e()[/color][/color][/color]
    (None, None)[color=blue][color=green][color=darkred]
    >>> locale.getdefau ltlocale()[/color][/color][/color]
    ('es_ES', 'cp1252')[color=blue][color=green][color=darkred]
    >>> locale.setlocal e(locale.LC_ALL , locale.getdefau ltlocale())[/color][/color][/color]
    Traceback (most recent call last):
    File "<interacti ve input>", line 1, in ?
    File "C:\Python23\li b\locale.py", line 381, in setlocale
    return _setlocale(cate gory, locale)
    Error: locale setting not supported

    That's the clincher: I can't seem to set locales. Why is this? IS there
    a way to get around this?

    I'm using python 2.3 under Windows XP and 2K.

    Moof



  • дамјан г.

    #2
    Re: Python Locales under windows

    [color=blue][color=green][color=darkred]
    > >>> print "%.2f" % 1024.36 # should be '1024,36'[/color][/color]
    > 1024.36[/color]

    [Linux/ Python-2.3.1]
    well this doesnt work under Linux neither, you need to use:

    locale.format( "%.2f", 1024.36)

    after setting the locale
    [color=blue][color=green][color=darkred]
    > >>> string.letters #should be 54 letters here, including ñÑ[/color][/color]
    > 'abcdefghijklmn opqrstuvwxyzABC DEFGHIJKLMNOPQR STUVWXYZ'[/color]

    Its the same here even afer locale was set, but maybe thats because my Linux
    locale is mk_MK.UTF8

    [color=blue]
    > I'm using python 2.3 under Windows XP and 2K.[/color]

    There is "locale.windows _locale" that may help you, although I don't
    knowwhat this dictionary is about.

    --
    Дамјан (jabberID:damja n@bagra.net.mk)

    There's no place like ~

    Comment

    Working...