
Ohne weitere Worte: ------------------ (ABSCHNEIDEN HIER) ------------ import time, sys, locale print "Python ist %s" % str(sys.version) default = locale.getdefaultlocale() print "default locale ist %s" % str(default) # laut doku zu strftime ist, Zitat # "%c Locale's appropriate date and time representation " print 'Das ist aber keine Deutsche Datumsangabe: %s' % time.strftime("%c") # das ist auch toll: try: locale.setlocale(locale.LC_ALL, default[0]) except Exception, e: print "setlocale('%s') schlägt fehl: %s" % (default[0], e) # undokumentiert, geht aber offensichtlich locale.setlocale(locale.LC_ALL, "german") # dokumentiert, geht aber nicht: try: print locale.D_T_FMT except AttributeError, e: print "locale.D_T_FMT gibt es nicht: %s" % str(e) # abgesehen davon, daß weder asctime noch localtime die locale # berücksichtigen (aber gut, das ist zumindest dokumentiert) print "Endlisch: %s" % time.strftime("%c") ------------------ (ABSCHNEIDEN HIER) ------------ Das Ergebnis
pythonw -u localesaugt.py sys:1: DeprecationWarning: Non-ASCII character '\xe4' in file localesaugt.py on line 17, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details Python ist 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] default locale ist ('de_DE', 'cp1252') Das ist aber keine Deutsche Datumsangabe: 08/01/03 09:37:17 setlocale('de_DE') schlägt fehl: locale setting not supported locale.D_T_FMT gibt es nicht: 'module' object has no attribute 'D_T_FMT' Endlisch: 01.08.2003 09:37:17 Exit code: 0
Wobei mir die DeprecationWarning da GERADE noch gefehlt hat. Grmpf...... _______________________________________________ Python-de maillist - Python-de@python.net http://python.net/mailman/listinfo/python-de

Hmmm, sieht bei mir ganz anders aus, differiert aber auch: $:~ > python2.3 gerson.py sys:1: DeprecationWarning: Non-ASCII character '\xe4' in file gerson.py on line 17, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details Python ist 2.3 (#1, Jul 30 2003, 16:46:58) [GCC 2.95.3 20010315 (SuSE)] default locale ist ('de_DE', 'iso-8859-15') Das ist aber keine Deutsche Datumsangabe: Fri Aug 1 11:47:33 2003 131112 Endlisch: Fre 01 Aug 2003 11:47:33 CEST $:~ > Viele Grüße Tino _______________________________________________ Python-de maillist - Python-de@python.net http://python.net/mailman/listinfo/python-de

Gerson Kurz <gerson.kurz@pergamon-software.de> wrote:
Ohne weitere Worte:
------------------ (ABSCHNEIDEN HIER) ------------ [abgeschnitten] ------------------ (ABSCHNEIDEN HIER) ------------ Das Ergebnis
pythonw -u localesaugt.py sys:1: DeprecationWarning: Non-ASCII character '\xe4' in file localesaugt.py on line 17, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details Python ist 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] default locale ist ('de_DE', 'cp1252') Das ist aber keine Deutsche Datumsangabe: 08/01/03 09:37:17 setlocale('de_DE') schlägt fehl: locale setting not supported locale.D_T_FMT gibt es nicht: 'module' object has no attribute 'D_T_FMT' Endlisch: 01.08.2003 09:37:17 Exit code: 0
Das Saugen der Locale ist zumindest auch vom OS abhängig ;-) : $ python2.3 /tmp/testlocale.py sys:1: DeprecationWarning: Non-ASCII character '\xe4' in file /tmp/testlocale.py on line 17, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details Python ist 2.3c1 (#1, Jul 23 2003, 14:15:38) [GCC 2.95.3 20010315 (SuSE)] default locale ist ('de_DE', 'iso-8859-15') Das ist aber keine Deutsche Datumsangabe: Fri Aug 1 11:39:57 2003 131112 Endlisch: Fre 01 Aug 2003 11:39:57 CEST $
Wobei mir die DeprecationWarning da GERADE noch gefehlt hat. Grmpf......
Grmpf ack ... Detlef -- Nothing sucks like an Electrolux. _______________________________________________ Python-de maillist - Python-de@python.net http://python.net/mailman/listinfo/python-de

Gerson Kurz wrote:
default = locale.getdefaultlocale() print "default locale ist %s" % str(default)
Bei mir passiert folgendes (Suse 8.1): Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.2/locale.py", line 337, in getdefaultlocale return _parse_localename(localename) File "/usr/lib/python2.2/locale.py", line 271, in _parse_localename raise ValueError, 'unknown locale: %s' % localename ValueError: unknown locale: de_DE@euro
# laut doku zu strftime ist, Zitat # "%c Locale's appropriate date and time representation "
print 'Das ist aber keine Deutsche Datumsangabe: %s' % time.strftime("%c")
http://www.python.org/doc/current/lib/node264.html Initially, when a program is started, the locale is the "C" locale, no matter what the user's preferred locale is. The program must explicitly say that it wants the user's preferred locale settings by calling setlocale(LC_ALL, ''). Funktioniert also exakt wie dokumentiert. Interessanterweise funktioniert die Umstellung bei mir trotz des obigen Problems mit dem "...@euro". Getdefaultlocale() scheint also eher etwas uebervorsichtig zu sein.
# das ist auch toll: try: locale.setlocale(locale.LC_ALL, default[0]) except Exception, e: print "setlocale('%s') schlägt fehl: %s" % (default[0], e)
# undokumentiert, geht aber offensichtlich locale.setlocale(locale.LC_ALL, "german")
# dokumentiert, geht aber nicht: try: print locale.D_T_FMT except AttributeError, e: print "locale.D_T_FMT gibt es nicht: %s" % str(e)
http://www.python.org/doc/current/lib/module-locale.html The locale module is implemented on top of the _locale module, which in turn uses an ANSI C locale implementation if available. Schlüsselwort: "if available". Also ist es in diesem Punkt wahrscheinlich eher dein OS, welches saugt, nicht das Python locale Modul. Wahrscheinlich hättest du jetzt gerne, dass das locale Modul alle Inkonsistenzen und Bugs der jeweiligen OS-Implementation abfängt, und gleich auch noch alle denkbaren Fehlkonfigurationen. Dem Wunsch als solchem kann ich mich durchaus anschliessen, ich weiss allerdings nicht, ob das mit vertretbarem Aufwand zu realisieren waere. Aber die Maintainer werden sich ueber entsprechende Patches sicher freuen... -schorsch -- Georg Mischler -- simulations developer -- schorsch at schorsch com +schorsch.com+ -- lighting design tools -- http://www.schorsch.com/ _______________________________________________ Python-de maillist - Python-de@python.net http://python.net/mailman/listinfo/python-de

Georg Mischler <schorsch@schorsch.com> writes:
Funktioniert also exakt wie dokumentiert. Interessanterweise funktioniert die Umstellung bei mir trotz des obigen Problems mit dem "...@euro". Getdefaultlocale() scheint also eher etwas uebervorsichtig zu sein.
getdefaultlocale ist schlicht unbrauchbar.
Wahrscheinlich hättest du jetzt gerne, dass das locale Modul alle Inkonsistenzen und Bugs der jeweiligen OS-Implementation abfängt, und gleich auch noch alle denkbaren Fehlkonfigurationen. Dem Wunsch als solchem kann ich mich durchaus anschliessen, ich weiss allerdings nicht, ob das mit vertretbarem Aufwand zu realisieren waere. Aber die Maintainer werden sich ueber entsprechende Patches sicher freuen...
Das hängt stark von den Patches ab. Ich möchte *nicht* Megabytes von locale-Daten in der Python-Distribution haben, die dann in ihrer Funktion davon abweichen, wie sich das lokale Betriebssytem verhält. Ciao, Martin _______________________________________________ Python-de maillist - Python-de@python.net http://python.net/mailman/listinfo/python-de
participants (5)
-
Detlef Lannert
-
Georg Mischler
-
Gerson Kurz
-
martin@v.loewis.de
-
Tino Lange