我正在尝试将 XML 文件转换为 CSV,但 XML 的编码(“ISO-8859-1”)显然包含 Python 用来写入行的 ascii 编解码器中没有的字符。
我得到错误:
Traceback (most recent call last):
File "convert_folder_to_csv_PLAYER.py", line 139, in <module>
xml2csv_PLAYER(filename)
File "convert_folder_to_csv_PLAYER.py", line 121, in xml2csv_PLAYER
fout.writerow(row)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 4: ordinal not in range(128)
我尝试按如下方式打开文件:
dom1 = parse(input_filename.encode( "utf-8" ) )
并且我尝试在写入之前替换每行中的 \xe1 字符。有什么建议么?