Re: Windows XP - Environment variable - Unicode

Discussion in 'Python' started by Alan Kennedy, Jul 11, 2003.

  1. Alan Kennedy

    Alan Kennedy Guest

    "sebastien.hugues" wrote:

    > Actually the issue is that this variable is
    > set by the system itself. It is not accessible from the control panel.
    > In the other hand, i don't use any terminal.
    >
    > So the question is how to get the default encoding of the system ?
    > I was looking for a while in win32api documentation, msdn and
    > Google but i didn't get nothing.


    This page from MSDN explains about how locales are handled for
    different users.

    http://msdn.microsoft.com/msdnnews/2001/july/Spotlight/Spotlight.asp

    Quoting: (for the archives, since MS are guaranteed to make the above
    link break sometime)

    """
    The System Default Locale

    The system default locale acts as an ANSI simulation layer. It
    determines the ANSI code page that the system uses when running a
    non-Unicode application. For example, if the system default locale is
    Japanese, then to a non-Unicode application the operating system will
    behave similarly to a Japanese operating system, fully able to support
    non-Unicode Japanese applications, but unable to support
    non-Japanese-compatible applications (such as a Korean non-Unicode
    app). The operating system uses the Japanese code page 932 when
    ANSI-Unicode translation is needed. So, the system default locale
    determines whether or not your non-Unicode application will run.

    The system default locale is set at installation, but can be changed
    in the Control Panel. To get the current system default locale, call
    the GetSystemDefaultLCID function.

    The User Locale and the Thread Locale

    The user locale and the thread locale determine which settings are
    used for formatting dates, times, currency, and large numbers as a
    default for each user. The user locale and the thread locale also
    determine the sort order for sorting text. The thread locale can be
    set separately for each thread. When the thread locale and the user
    locale are different, the thread locale overrides the user locale.
    For example, even though your app is English and the system default
    locale is English, as long as the user locale is Spanish (and you did
    not set the thread locale specifically), your strings will be sorted
    by the Spanish sorting order. If you need your app's numbers,
    currency, or sorting to be done in a certain locale, make sure that
    you set the thread locale explicitly by calling the SetThreadLocale
    function.
    When each thread starts, the thread locale defaults to the user
    locale. The user locale defaults to the locale that matches the
    language of the localized system. To get the user locale, call the
    GetUserDefaultLCID function. Call the GetThreadLocale function to get
    the calling thread locale.
    """

    I'm not sure if the env var you're looking at is set in the system or
    user default locale, so probably best to try both:-

    systemdefaultlcid = win32api.GetSystemDefaultLCID()
    userdefaultlcid = win32api.GetUserDefaultLCID()

    http://aspn.activestate.com/ASPN/Py...ions/win32api__GetUserDefaultLangID_meth.html

    Now, as for how to turn an LCID into a character set name, I don't
    know the answer to that one :-(

    Here's a q&d hack for getting the user default character set, through
    an internet explorer COM object.

    from win32com.client import Dispatch
    htmldoc = Dispatch("htmlfile")
    htmldoc.writeln("<h1>any old stuff</h1>")
    print htmldoc.defaultCharset

    HTH,

    --
    alan kennedy
    -----------------------------------------------------
    check http headers here: http://xhaus.com/headers
    email alan: http://xhaus.com/mailto/alan
    Alan Kennedy, Jul 11, 2003
    #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. sebastien.hugues

    Windows XP - Environment variable - Unicode

    sebastien.hugues, Jul 11, 2003, in forum: Python
    Replies:
    8
    Views:
    598
    John Roth
    Jul 13, 2003
  2. Fuzzyman

    Set Windows Environment Variable

    Fuzzyman, Mar 30, 2006, in forum: Python
    Replies:
    6
    Views:
    8,578
    Fuzzyman
    Mar 30, 2006
  3. Replies:
    5
    Views:
    637
  4. Pavel Ledin

    Setting Windows environment variable

    Pavel Ledin, Sep 20, 2006, in forum: Ruby
    Replies:
    2
    Views:
    147
    Pavel Ledin
    Sep 20, 2006
  5. Hans
    Replies:
    2
    Views:
    304
Loading...

Share This Page