eryksun added the comment:

> import locale
> locale.setlocale(locale.LC_ALL, '')
>
> import importlib
> import time
> importlib.reload(time)
>
> it does not work when imported after importing time. 
> What is the reason? Does reload() work only for 
> modules coded as Python sources? 

The import system won't reinitialize a builtin or dynamic extension module. 
Reloading just returns a reference to the existing module. It won't even reload 
a PEP 489 multi-phase extension module. (But you can create and exec a new 
instance of a multi-phase extension module.) 

> Is there any other approach that would implement the 
> workaroundXXX.py module?

If the user's default locale and the current thread's preferred language are 
compatible with the system ANSI encoding [1], then you don't actually need to 
call _tzset nor worry about time.tzname. Call setlocale(LC_CTYPE, ''), and then 
call time.strftime('%Z') to get the timezone name. 

If you use Win32 directly instead of the CRT, then none of this ANSI business 
is an issue. Just call GetTimeZoneInformation to get the standard and daylight 
names as wide-character strings. You have that option via ctypes.

[1]: A user can select a default locale (language) that's unrelated to the 
system ANSI locale (the ANSI setting is per machine, located under 
Region->Administrative). Also, the preferred language can be selected 
dynamically by calling SetThreadPreferredUILanguages or 
SetProcessPreferredUILanguages. All three could be incompatible with each 
other, in which case you have to explicitly set the locale (e.g. "ru-RU" 
instead of an empty string) and call _tzset.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16322>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to