Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'win32': 0.03; 'encoding': 0.05; 'output': 0.05; 'startup': 0.05; 'sufficient': 0.05; 'locale': 0.09; 'none)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'try:': 0.09; 'runs': 0.10; 'python': 0.11; 'jan': 0.12; "'''": 0.16; "'');": 0.16; '(none,': 0.16; 'imports': 0.16; 'list)': 0.16; 'notation': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'slightly': 0.19; 'import': 0.22; 'header:User- Agent:1': 0.23; 'skip:l 30': 0.24; 'environment': 0.24; 'question': 0.24; '2010,': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'skip:( 20': 0.30; 'code': 0.31; '"")': 0.31; '>>>>': 0.31; 'values.': 0.31; 'idle': 0.36; 'instances': 0.36; 'hi,': 0.36; 'nov': 0.38; 'to:addr :python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'more': 0.64; 'different': 0.65; 'subject:. ': 0.67; '2.7.1': 0.84; 'received:fios.verizon.net': 0.84; 'subject:skip:l 10': 0.84; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: locale.getlocale() in cmd.exe vs. Idle Date: Mon, 10 Nov 2014 15:31:34 -0500 References: <37011265.138748.1415611323250.JavaMail.yahoo@jws10709.mail.gq1.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-108-16-203-145.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <37011265.138748.1415611323250.JavaMail.yahoo@jws10709.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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 57 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415651514 news.xs4all.nl 2932 [2001:888:2000:d::a6]:57919 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80489 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? > > # IDLE > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license()" for more information. >>>> import locale >>>> locale.getdefaultlocale() > ('nl_NL', 'cp1252') >>>> locale.getlocale() > ('Dutch_Netherlands', '1252') # I need this specific notation >>>> > > # cmd.exe or Ipython > C:\Users\albertjan>python > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import locale >>>> locale.getdefaultlocale() > ('nl_NL', 'cp1252') >>>> locale.getlocale() > (None, None) > > # using setlocale does work (one of these instances when I answer my own question while writing to the Python list) > C:\Users\albertjan>python > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import locale >>>> locale.setlocale(locale.LC_ALL, "") > 'Dutch_Netherlands.1252' >>>> locale.getlocale() > ('Dutch_Netherlands', '1252') 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, "") ''' idlelib.run, which runs in the user-code subprocess, imports IOBinding. Setting LC_CTYPE is sufficient for getlocale() to not return null values. 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') -- Terry Jan Reedy