Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Windows XP - Environment variable - Unicode (http://www.velocityreviews.com/forums/t319556-re-windows-xp-environment-variable-unicode.html)

Alan Kennedy 07-11-2003 03:42 PM

Re: Windows XP - Environment variable - Unicode
 
"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/2.../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/Pyt...ngID_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


All times are GMT. The time now is 01:28 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.