[python-win32] LOCALE related stuff Re: Setting environment variables in windows from Python Programs-

Tim Roberts timr at probo.com
Wed May 11 21:05:55 CEST 2005


Nalli Dinesh wrote:

>I using locale.setlocale and u guys know when we use this setlocale.
>Yes I am working on Localising my application-a pygtk application.
>When one says 
>import locale
>locale.setlocale(locale.LC_ALL, ' ')
>  
>

You don't really have a blank space between those quotes, do you?

>This sets the locale for all categories to the user's default setting
>(typically specified in the LANG environment variable).
>I use Python2.4
>Before I start my application from the DOS command prompt, run this
>command at the cmd prompt to set LANG environment. Which is "set
>LANG=ja_JP"
>And now if I run my python(that uses pygtk ) application it starts up
>and locale.setlocale able to read this LANG variable and do the needed
>setting for the locale.
>But if I don;t define this variable at the command prompt before I
>start the python application, but I define the environmen variable
>LANG like os.environ['LANG'] = 'ja_JP'.
>Then the setlocale doesn't set the locale as needed.
>  
>

When do you set the variable?  It must be before ANY import that might 
read the locale.  So, for example, the first lines of your file might 
need to be:
    import os
    os.environ['LANG'] = 'ja_JP'
    import locale
    locale.setlocale(locale.LC_ALL, '')
    import sys
    import pygtk
    ...

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-win32 mailing list