habe aktuell folgendes Problem:
Ich lese ein Textfile ein und bekomme:
File "/usr/local/lib/python3.1/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf6 in position 15: ordinal not in range(128)
Jetzt habe ich das hier gelesen:
http://www.python-forum.de/viewtopic.php?f=1&t=17437
und ein line=iso88591.decode(line) eingefuegt:
Code: Alles auswählen
#dateistr=""
dateistr=iso88591.decode("")
for line in objects_f:
line=iso88591.decode(line)
if not line.startswith('#'):
dateistr += line
NameError: global name 'iso88591' is not defined
dann hab ich oben noch:
# -*- coding: iso-8859-1 -*- eingefuegt
und hab noch immer den Fehler (und frage mcih auch was die Zeile soll= (denn meine.py ist ja ascii))
oder so:
Code: Alles auswählen
dateistr=""
# Text definieren
# s_iso88591 = "Hallo .."
# Text nach Unicode umwandeln
# s_unicode = s_iso88591.decode("iso-8859-1")
dateistr = dateistr.decode("iso-8859-1")
und kenne mich nun gar nicht mehr aus
Dann hab ich mal den ganzen Code aus dem Posting (http://www.python-forum.de/viewtopic.php?f=1&t=17437) getestet:
Code: Alles auswählen
python3.1
Python 3.1.2 (r312:79147, Feb 11 2011, 21:32:43)
[GCC 4.2.1 20070719 [FreeBSD]] on freebsd8
Type "help", "copyright", "credits" or "license" for more information.
>>> # -*- coding: iso-8859-1 -*-
...
... # Text definieren
... s_iso88591 = "Hallo \xd6sterreich"
>>>
... # Text nach Unicode umwandeln
... s_unicode = s_iso88591.decode("iso-8859-1")
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
AttributeError: 'str' object has no attribute 'decode'
>>>
... # Text nach UTF-8 umwandeln
... s_utf8 = s_unicode.encode("utf-8")
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
NameError: name 's_unicode' is not defined
Gruss Torres