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


Groups > comp.lang.python > #68294

Re: locale getlocale returns None on OSX

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <fomcl@yahoo.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'output': 0.05; '(python': 0.07; 'pypy': 0.07; 'python3': 0.07; 'wednesday,': 0.07; 'locale': 0.09; 'none)': 0.09; 'outlined': 0.09; 'subject:None': 0.09; 'python': 0.11; '2.7': 0.14; '"python': 0.16; '(none,': 0.16; '2.2.1': 0.16; '2.7.3': 0.16; 'called.': 0.16; 'surprises': 0.16; 'x86_64': 0.16; 'variable': 0.18; 'examples': 0.20; 'feb': 0.22; '>>>': 0.22; 'example': 0.22; 'import': 0.22; 'tests': 0.22; 'print': 0.22; 'this?': 0.23; 'skip:l 30': 0.24; 'environment': 0.24; 'equivalent': 0.26; 'first,': 0.26; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'skip:( 40': 0.30; 'code': 0.31; "skip:' 10": 0.31; '"")': 0.31; '>>>>': 0.31; 'gcc': 0.31; 'skip:= 20': 0.31; 'supposed': 0.32; 'another': 0.32; 'linux': 0.33; 'header:Received:9': 0.33; 'problem': 0.35; 'something': 0.35; 'but': 0.35; 'skip:> 10': 0.36; 'starting': 0.37; 'sometimes': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; '12,': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'even': 0.60; 'received:98.137': 0.60; 'march': 0.61; 'here:': 0.62; 'kind': 0.63; 'more': 0.64; 'here': 0.66; 'header :Reply-To:1': 0.67; 'mar': 0.68; 'to:addr:yahoo.com': 0.81; '2.7.': 0.84; '2014,': 0.84; 'system:': 0.91
X-Yahoo-Newman-Property ymail-4
X-Yahoo-Newman-Id 479941.35824.bm@omp1007.mail.gq1.yahoo.com
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1394653227; bh=oZpwPQq4g0PYWEaBnAqJ6LHUzKHnk4LymL8JA2PKlJw=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=03Dhg1TIa8UKW/Xc7GZ2Uf6pIU1vpid4ljpCeftGAzGZobEJe+h75SXb6GWjsaLXyPRtWaujRbwrUW7ADebJytSrh32Sl2+UlaSB3nd7c07/i9tPa414kbftzPxWdq8/ED59lvdaZXadUdX64QP2BeCiYLQ6wmypCQCz5G4tkFQ=
DomainKey-Signature a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=g+TtWvN6lNtFxBQe1COUYM6xmCgxUGhEgBuHTja2Q6+1uaC1Pn57SgDkRjROHfbsOcxUUZcbrNz3keNsB4BKXaV0uq/yarhDPF5KWjJR0nB6OH+FZrbf+87pMUuVDCyZA1AS474D7tEbr5XwEh3GRFEyngptNTvq/Af9EQ9t510=;
X-YMail-OSG 5Ob.jzQVM1klOWP.FFL0nbrjGIDN7gKcxV.07pdC7L9RzJw .g69u0LowQ7.ZvVYXFlFoNTV8rvbdRx.D7BjInWFogGKCcfeBD2Ua36Lqj0u KwQQoAX6ODMge.hUPP5PWEcA1UlDYSaGUxNRaVWsksYEhkn2rRA68J.6BD0V zz47RGkqcf41UuL4kpXOwuL7SJXxWLXY4Dm2WPV0qaiVdgaRQA7fAkC5FvQD xwfNfDZwvI7bM6Ak_4PxQL2h.KuWPuXzlxTL1k3qCofFMeStffBRHdydMXUn VDqlPeZ5tb8.fjCrkrgMnnrpKYiGtfxYXDRqebgij6jWytIr5XFORn5cwTLW 2qlfNLOfj6_AKAwZa3jg.auel9KRfzOFCXSHhZ9WFu9Wofiw6Ojz7Un5Jyo7 gwWU51PitJFQIqrabsGEmIYjfsU58tCESOE5b7Ezm0EquAmQ2f08aUh.poYj S8Nxbi4QryLyDL4dC90WZrx7YntJWAduyoN.zEos_rs5KKd1dlUitJKFBId. U.2Vt2VEyXuG7Kn.OeDJaKBchi211480z3QnkiUfsnb2s85b3UOQOd60CpF6 .gGb5yDCY5S11zdJ.twdjnVuUVcJVxbMy0EBBJwsCY6lRMAkba3jow0vl4X5 3k9tnRrVvBlWtbu4yPv07YS7fejuXfiQtwGMNS5QR.oXHsp2UbzUpimHgwuc zTPdY90.Bt03Syvp0f6cIQaV_5eSmugPxbhWKfbPORVE-
X-Rocket-MIMEInfo 002.001, Cgo.X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KPiBGcm9tOiBBbGJlcnQtSmFuIFJvc2thbSA8Zm9tY2xAeWFob28uY29tPgo.VG86IFB5dGhvbiA8cHl0aG9uLWxpc3RAcHl0aG9uLm9yZz4gCj5TZW50OiBXZWRuZXNkYXksIE1hcmNoIDEyLCAyMDE0IDE6MjIgUE0KPlN1YmplY3Q6IGxvY2FsZSBnZXRsb2NhbGUgcmV0dXJucyBOb25lIG9uIE9TWAo.IAo.Cj5IaSwKPgo.bG9jYWxlLmdldGxvY2FsZSgpIHNvbWV0aW1lcyByZXR1cm5zIChOb25lLCBOb25lKSB1bmRlciBPU1ggKFB5dGhvbiAyLCABMAEBAQE-
X-Mailer YahooMailWebService/0.8.177.636
References <1394626979.46880.YahooMailBasic@web163806.mail.gq1.yahoo.com>
Date Wed, 12 Mar 2014 12:40:27 -0700 (PDT)
From Albert-Jan Roskam <fomcl@yahoo.com>
Subject Re: locale getlocale returns None on OSX
To Albert-Jan Roskam <fomcl@yahoo.com>, Python <python-list@python.org>
In-Reply-To <1394626979.46880.YahooMailBasic@web163806.mail.gq1.yahoo.com>
MIME-Version 1.0
Content-Type text/plain; charset=iso-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To Albert-Jan Roskam <fomcl@yahoo.com>
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.8100.1394653528.18130.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1394653528 news.xs4all.nl 2936 [2001:888:2000:d::a6]:39674
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:68294

Show key headers only | View raw



>________________________________
> From: Albert-Jan Roskam <fomcl@yahoo.com>
>To: Python <python-list@python.org> 
>Sent: Wednesday, March 12, 2014 1:22 PM
>Subject: locale getlocale returns None on OSX
> 
>
>Hi,
>
>locale.getlocale() sometimes returns (None, None) under OSX (Python 2, not sure about Python 3, but I think so). The problem is outlined here:
>http://stackoverflow.com/questions/1629699/locale-getlocale-problems-on-osx
>
>What is the cause of this? Is it limited to just Darwin systes? Does the 'horrible hack' solution on OS have any drawbacks? I like it better because it is not needed to set the LC_ALL environment variable prior to starting the Python program.
>
>Regards,
>
>Albert-Jan


Ok, here are some tests on my own system:

albertjan@debian:~$ uname -a
Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux


Even if locale.setlocale is used first, OSX returns (None, None) when locale.getlocale() is called. Another thing that surprises me in the examples below is the output of the "python -c" example using Python 2.7. Isn't this supposed to be exactly equivalent to the code that follows?



# ======== Python 2.7 ========albertjan@debian:~$ python -c "import locale; locale.setlocale(locale.LC_ALL, ""); print(locale.getlocale())"

(None, None)   # <---- why is this?


albertjan@debian:~$ python
Python 2.7.3 (default, Jan  2 2013, 13:56:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "")
'en_US.UTF-8'
>>> locale.getlocale()
('en_US', 'UTF-8')  # <--- OSX (sometimes?) returns (None, None) here.



# ======== Python 3.3 ========
albertjan@debian:~$ python3 -c "import locale; locale.setlocale(locale.LC_ALL, ""); print(locale.getlocale())"
('en_US', 'UTF-8')

albertjan@debian:~$ python3
Python 3.3.4 (default, Feb 17 2014, 19:23:00) 
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "")
'en_US.UTF-8'
>>> locale.getlocale()
('en_US', 'UTF-8')



# ======== Pypy ========
albertjan@debian:~$ pypy -c "import locale; locale.setlocale(locale.LC_ALL, ""); print locale.getlocale()"
(None, None)

albertjan@debian:~$ pypy

Python 2.7.3 (87aa9de10f9ca71da9ab4a3d53e0ba176b67d086, Mar 10 2014, 14:07:15)
[PyPy 2.2.1 with GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``pypy is a better kind of
foolishness - lac''
>>>> import locale
>>>> locale.setlocale(locale.LC_ALL, "")
'en_US.UTF-8'
>>>> locale.getlocale()
('en_US', 'UTF-8')

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


Thread

Re: locale getlocale returns None on OSX Albert-Jan Roskam <fomcl@yahoo.com> - 2014-03-12 12:40 -0700

csiph-web