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


Groups > comp.lang.python > #80538

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

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <random832@fastmail.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'encoding': 0.05; 'output': 0.05; 'startup': 0.05; 'sufficient': 0.05; 'derived': 0.09; 'exception.': 0.09; 'locale': 0.09; 'none)': 0.09; 'received:internal': 0.09; 'try:': 0.09; 'runs': 0.10; 'python': 0.11; 'bug': 0.12; "'''": 0.16; "'');": 0.16; '(none,': 0.16; '(sorry,': 0.16; '__init__.py': 0.16; 'docstrings': 0.16; 'imports': 0.16; 'it),': 0.16; 'matters,': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:messagingengine.com': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'slightly': 0.19; '>>>': 0.22; 'appears': 0.22; 'import': 0.22; 'error': 0.23; 'skip:l 30': 0.24; 'environment': 0.24; 'question': 0.24; 'switch': 0.26; 'header:In- Reply-To:1': 0.27; 'idea': 0.28; 'function': 0.29; '(this': 0.29; 'am,': 0.29; 'related': 0.29; 'url:mailman': 0.30; 'code': 0.31; "skip:' 10": 0.31; '"")': 0.31; 'values.': 0.31; 'url:python': 0.33; '-----': 0.33; 'monday,': 0.33; 'actual': 0.34; "i'd": 0.34; 'received:66': 0.35; 'except': 0.35; 'something': 0.35; 'but': 0.35; 'doubt': 0.36; 'idle': 0.36; 'in.': 0.36; 'raising': 0.36; 'url:listinfo': 0.36; 'possible': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'should': 0.36; 'email addr:python.org': 0.37; 'received:10': 0.37; 'thank': 0.38; 'nov': 0.38; 'same.': 0.38; 'to:addr:python-list': 0.38; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'system.': 0.39; 'skip:p 20': 0.39; 'url:mail': 0.40; 'even': 0.60; 'from:no real name:2**0': 0.61; 'you.': 0.62; 'header:Message-Id:1': 0.63; 're:': 0.63; 'more': 0.64; 'different': 0.65; 'email name:python-list': 0.65; 'subject:. ': 0.67; 'between': 0.67; 'to,': 0.72; 'introduce': 0.78; '(always': 0.84; '2014,': 0.84; 'partially': 0.84; 'subject:skip:l 10': 0.84
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.us; h= message-id:x-sasl-enc:from:to:mime-version :content-transfer-encoding:content-type:subject:date:in-reply-to :references; s=mesmtp; bh=wTgQprSlSKorXcqZngc7Ul9gM3Q=; b=jOwp3Q aSDK3ezXtsqRMEBRPAWu+al4Hs3+KikCAz9jKpLHFPXdX1/S3S1r5bjqqrNA8i01 YDI5z9TRbE8Ci0AFPogTLm6aNdhV2ZMpjTx38p/oNGvMP5OUpPd4svWuQt5SZK9D sS2yJAMEBKfEUY0hLYncux2bJEZ1oodjAwdXU=
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:x-sasl-enc:from:to :mime-version:content-transfer-encoding:content-type:subject :date:in-reply-to:references; s=smtpout; bh=wTgQprSlSKorXcqZngc7 Ul9gM3Q=; b=iVXm1pXUNRMtHhABdcU2uao4DSeJOT5C3BJcLs6Ske3CUN1c7i4Z 52s7YniGCgZvcLYdtTfBCoAY0hDGPqQZSWjwl9Db+kIjzvio/HM4SWI5lqSBuS2N vUryvP/CV/FHWl777IhVj1IlCDKxCoBXM8E9ytY2wue8S+bsCxc2zyA=
X-Sasl-Enc e+ZSHJAaLv/ioyoLlOPe5i/mYBvW6oEd11sKLGbAtLMZ 1415726414
From random832@fastmail.us
To python-list@python.org
MIME-Version 1.0
Content-Transfer-Encoding 7bit
Content-Type text/plain
X-Mailer MessagingEngine.com Webmail Interface - ajax-9183bd94
Subject Re: locale.getlocale() in cmd.exe vs. Idle
Date Tue, 11 Nov 2014 12:20:14 -0500
In-Reply-To <595961668.36331.1415717221155.JavaMail.yahoo@jws10713.mail.gq1.yahoo.com>
References <m3r7bc$nun$1@ger.gmane.org> <595961668.36331.1415717221155.JavaMail.yahoo@jws10713.mail.gq1.yahoo.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15676.1415726417.18130.python-list@python.org> (permalink)
Lines 79
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415726417 news.xs4all.nl 2838 [2001:888:2000:d::a6]:38373
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80538

Show key headers only | View raw



On Tue, Nov 11, 2014, at 09:47, Albert-Jan Roskam wrote:
> ----- 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?

setlocale returns the actual value that the locale was set to, which is
often (always in case of "") not the same as the value that was passed
in. The C function it is based on would return NULL on an error instead
of raising an exception.

>>> locale.setlocale(locale.LC_CTYPE,"")
'en_US.UTF-8'


 (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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: locale.getlocale() in cmd.exe vs. Idle random832@fastmail.us - 2014-11-11 12:20 -0500

csiph-web