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

random832 at fastmail.us random832 at fastmail.us
Tue Nov 11 18:18:40 CET 2014



On Tue, Nov 11, 2014, at 09:47, Albert-Jan Roskam wrote:
> ----- Original Message -----
> > From: Terry Reedy <tjreedy at udel.edu>
> > To: python-list at 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?

setlocale returns the actual value that the locale was set to.


 (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
> -- 
> https://mail.python.org/mailman/listinfo/python-list


-- 
Random832



More information about the Python-list mailing list