Ich möchte mit lxml eine xml-datei parsen und die Daten dann auch irgendwie darstellen. In der xml sind allerdings auch Umlaute. Wie bringe ich Python jetzt dazu mir das richtig anzuzeigen?
Code: Alles auswählen
#coding: iso-8859-1
from lxml import objectify
file = open ("file.xml")
tree = objectify.parse(file)
tags = tree.xpath("//tag")
for tag in tags:
print tag.id, tag.name
In dem angegebenen coding ist die Datei auch abgespeichert. Und die xml-Datei hat das selbe coding. Was passt also nicht?File "pythprob.py", line 9, in <module>
print tag.id, tag.name
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 3: ordinal not in range(128)
€: http://www.python-forum.de/topic-5095.html hab ich schon gefunden. Hat mir aber irgendwie nicht wirklich weiter geholfen.