Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80526 > unrolled thread

Re: locale.getlocale() in cmd.exe vs. Idle

Started byAlbert-Jan Roskam <fomcl@yahoo.com>
First post2014-11-11 14:47 +0000
Last post2014-11-11 14:47 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: locale.getlocale() in cmd.exe vs. Idle Albert-Jan Roskam <fomcl@yahoo.com> - 2014-11-11 14:47 +0000

#80526 — Re: locale.getlocale() in cmd.exe vs. Idle

FromAlbert-Jan Roskam <fomcl@yahoo.com>
Date2014-11-11 14:47 +0000
SubjectRe: locale.getlocale() in cmd.exe vs. Idle
Message-ID<mailman.15664.1415717406.18130.python-list@python.org>
----- Original Message -----
> From: Terry Reedy <tjreedy@udel.edu>
> To: python-list@python.org
> Cc: 
> Sent: Monday, November 10, 2014 9:31 PM
> Subject: Re: locale.getlocale() in cmd.exe vs. Idle
> 
> On 11/10/2014 4:22 AM, Albert-Jan Roskam wrote:
>>  Hi,
>> 
>>  Why do I get different output for locale.getlocale() in Idle vs. cmd.exe?

<snip>

> 
> Idle runs code in an environment that is slightly altered from the 
> standard python startup environment'.  idlelib.IOBinding has this
> '''
> # Try setting the locale, so that we can find out
> # what encoding to use
> try:
>      import locale
>      locale.setlocale(locale.LC_CTYPE, "")
> '''
 
Hi Terry,
 
Thank you. Any idea why setlocale (a *setter*) returns something other than None? (this question is not related to the (None, None) thing of getlocale, just curious). Would it be a good idea to put this setlocale line in site.py? Or should it be in __init__.py to make the code more portable?

> idlelib.run, which runs in the user-code subprocess, imports IOBinding. 
> Setting LC_CTYPE is sufficient for getlocale() to not return null values.

So then I would have all the locale categories of the 'bare' locale (sorry, I don't know what else I should call it), except for LC_CTYPE, which is derived from my system. So in LC_NUMERIC I'd still have the en_US period/comma for decimal/thousand grouping, respectively, but I switch to the nl_NL LC_CTYPE. I doubt if it matters, but still: will this not introduce an ueber hard-to-find possible bug when I use re.LOCALE? 
 
> C:\Users\Terry>python -c "import locale; 
> print(locale.getlocale())"
> 
> (None, None)
> 
> C:\Users\Terry>python -c "import locale; 
> locale.setlocale(locale.LC_CTYPE, ''); print(locale.getlocale())"
> ('English_United States', '1252')
 
What is the difference between getlocale and getdefaultlocale anyway? The docstrings are even partially the same. The notatation of getlocale appears to be OS-specific ("English_United States" in Windows) and not Unix-like (cf. getdefaultlocale: en_US)
 
regards,
Albert-Jan

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web