1
Ich versuche, eine UTF-8 XML-Datei mit Python 3 aber ich bin wirklich in Schwierigkeiten mit der Codierung zu lesen:Der Versuch, eine UTF-8 XML-Datei mit Python zu lesen 3
In [47]: fileObj = codecs.open(file, "r", "utf-8")
In [48]: fileObj.read()
Out[48]: ---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
<ipython-input-48-dd7cd49f4aa8> in <module>()
----> 1 fileObj.read()
~/Documents/Projects/project/env/lib/python3.6/site-packages/IPython/core/displayhook.py in __call__(self, result)
259 self.fill_exec_result(result)
260 if format_dict:
--> 261 self.write_format_data(format_dict, md_dict)
262 self.log_output(format_dict)
263 self.finish_displayhook()
~/Documents/Projects/project/env/lib/python3.6/site-packages/IPython/core/displayhook.py in write_format_data(self, format_dict, md_dict)
188 result_repr = '\n' + result_repr
189
--> 190 print(result_repr)
191
192 def update_user_ns(self, result):
UnicodeEncodeError: 'ascii' codec can't encode character '\u20ac' in position 1630: ordinal not in range(128)
Wo ich falsch liege?
Sie lesen ok. Ordnen Sie es einfach einer Variablen zu. Es ist ein Displayhook von IPython, der fehlschlägt. Wahrscheinlich haben Sie Ihre Terminalcodierung nicht korrekt konfiguriert. Auch 'codecs.open' ist unnötig und kann fehlerhaft sein. 'open' funktioniert in Python3 einwandfrei. –