Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86721
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2.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.006 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'broken': 0.04; 'output': 0.05; 'sys': 0.07; '"__main__":': 0.09; '__name__': 0.09; 'locale': 0.09; 'wrapper': 0.09; 'python': 0.11; 'def': 0.12; 'windows': 0.15; '@property': 0.16; 'bug:': 0.16; 'bugs.': 0.16; 'lang': 0.16; 'example': 0.22; 'import': 0.22; 'print': 0.22; 'skip:l 30': 0.24; 'code': 0.31; '"")': 0.31; 'libraries': 0.31; 'class': 0.32; 'thanks!': 0.32; 'worked': 0.33; 'skip:_ 10': 0.34; 'skip:s 30': 0.35; 'but': 0.35; 'done': 0.36; 'charset:us-ascii': 0.36; 'hi,': 0.36; 'skip:o 20': 0.38; 'sometimes': 0.38; 'system,': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:98.137': 0.60; 'received:gq1.yahoo.com': 0.68; 'received:mail.gq1.yahoo.com': 0.68; 'received:98.136': 0.69; 'apart': 0.72; 'received:bullet.mail.gq1.yahoo.com': 0.84; 'us?': 0.84; 'medicine,': 0.91; 'education,': 0.96 |
| X-Yahoo-Newman-Property | ymail-3 |
| X-Yahoo-Newman-Id | 548317.62422.bm@omp1025.mail.gq1.yahoo.com |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1425296569; bh=dhEaqPlytMUkbO2to6ZUZdc35FrcVwLSAe4ZRczzeIg=; h=Message-ID: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xvY2FsZS4gRXhhbXBsZSBidWc6IHJlc2V0bG9jYWxlIGZhaWxzIGluIFdpbmRvd3MuIFdoYXQgaXMgeW91ciBvcGluaW9uIGFib3V0IHRoZSB3b3JrLWFyb3VuZCBjb2RlIGJlbG93PyABMAEBAQE- |
| X-Mailer | YahooMailClassic/394 YahooMailWebService/0.8.203.740 |
| Date | Mon, 2 Mar 2015 03:42:49 -0800 |
| From | Albert-Jan Roskam <fomcl@yahoo.com> |
| Subject | Pythonic locale |
| To | Python <python-list@python.org> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| 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.31.1425296685.13471.python-list@python.org> (permalink) |
| Lines | 74 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1425296685 news.xs4all.nl 2962 [2001:888:2000:d::a6]:58245 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:86721 |
Show key headers only | View raw
Hi,
The Python locale standard libraries has some oddities and (long-standing) bugs.
Example oddity: SETlocale *returns* a locale; getlocale output cannot always be consumed by setlocale. Example bug: resetlocale fails in Windows. What is your opinion about the work-around code below?
import sys
import os
import locale as locale_
locale_.setlocale(locale_.LC_ALL, "")
class PythonicLocale(object):
LC_ALL = locale_.LC_ALL
LC_CTYPE = locale_.LC_CTYPE
def __init__(self, failsafe=False):
self.failsafe = failsafe
@property
def locale(self):
"""Partial wrapper for locale in standard library"""
# LANG and LC_ALL sometimes not set
if not sys.platform.startswith("win"):
if locale_.getlocale()[0] is None and self.failsafe:
os.environ["LANG"] = "en_US"
os.environ["LC_ALL"] = "en_US.UTF-8"
# getlocale output cannot be consumed by setlocale
return locale_.setlocale(locale_.LC_ALL)
@locale.setter
def locale(self, category_and_locale_tuple):
locale_.setlocale(*category_and_locale_tuple)
@locale.deleter
def locale(self):
if sys.platform.startswith("win"):
# resetlocale() is broken in Windows
locale_.setlocale(locale_.LC_ALL, "")
else:
locale_.resetlocale()
def getdefaultlocale(self):
return locale_.getdefaultlocale()
if __name__ == "__main__":
locale = PythonicLocale()
# getter
print locale.locale
# setter
locale.locale = (locale.LC_ALL, "german")
print locale.locale
# deleter
del locale.locale
# check if deleter worked
print locale.locale
Thanks!
Regards,
Albert-Jan
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Pythonic locale Albert-Jan Roskam <fomcl@yahoo.com> - 2015-03-02 03:42 -0800
csiph-web