Wie kriege ich einen Unicode-string in einen für uns lesbaren Text. Mit encode() scheint das nicht zu funktionieren.
test = u"äöüäö'" test u"\xe4\xf6\xfc\xe4\xf6'" test.encode('latin-1') "\xe4\xf6\xfc\xe4\xf6'" test.encode('utf-8') "\xc3\xa4\xc3\xb6\xc3\xbc\xc3\xa4\xc3\xb6'" test.encode('utf-16') "\xff\xfe\xe4\x00\xf6\x00\xfc\x00\xe4\x00\xf6\x00'\x00" test.encode('ascii') Traceback (most recent call last): File "<interactive input>", line 1, in ? UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)
Muss ich ausgehend von der 'latin-1' version ein global replace machen? Das kann es doch nicht sein... wie komme ich wieder an meine äs und ös etc.? Für jeden Hinweis dankbar, Merci, Marco _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
Marco Aschwanden wrote:
Wie kriege ich einen Unicode-string in einen für uns lesbaren Text. Mit encode() scheint das nicht zu funktionieren.
test = u"äöüäö'" test u"\xe4\xf6\xfc\xe4\xf6'" test.encode('latin-1') "\xe4\xf6\xfc\xe4\xf6'" test.encode('utf-8') "\xc3\xa4\xc3\xb6\xc3\xbc\xc3\xa4\xc3\xb6'" test.encode('utf-16') "\xff\xfe\xe4\x00\xf6\x00\xfc\x00\xe4\x00\xf6\x00'\x00" test.encode('ascii') Traceback (most recent call last): File "<interactive input>", line 1, in ? UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)
Muss ich ausgehend von der 'latin-1' version ein global replace machen? Das kann es doch nicht sein... wie komme ich wieder an meine äs und ös etc.?
Mit "ascii" garantiert nicht. Da sind keine Sonderzeichen enthalten. Die anderen Encodings scheinen ja alle zu funktionieren, also musst du nur noch festlegen, welches du wirklich haben willst. Wahrscheinlich haben dich die vielen '\x??' durcheinandergebracht. Setze den obigen Anweisungen doch mal jeweils ein print voraus, dann siehst du klarer. Der Haken liegt in der Unterscheidung zwischen str() und repr(). -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
On Wed, 7 Apr 2004 13:00:15 -0400 (EDT), Georg Mischler <schorsch@schorsch.com> wrote:
Wahrscheinlich haben dich die vielen '\x??' durcheinandergebracht. Setze den obigen Anweisungen doch mal jeweils ein print voraus, dann siehst du klarer. Der Haken liegt in der Unterscheidung zwischen str() und repr().
*schääm* Du hast natürlich absolut recht. Sorry... Grüsse aus dem kleinen Kanton, Marco _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
participants (2)
-
Georg Mischler
-
Marco Aschwanden