我有以下 XML:
newX.xml
<?xml version="1.0" encoding="UTF-8"?>
<data>
<country name="Liechtenstein">
<neighbor name="Austriaą" direction="E"/>
<neighbor name="a" direction="W"/>
</country>
</data>
Python脚本:
# -*- coding: cp1250 -*-
import xml.etree.ElementTree as ET
xml = 'c://newX.xml'
tree = ET.parse(xml)
root = tree.getroot()
for rank in root.iter('neighbor'):
rank.set('name', 'ą')
ET.dump(root)
我正在尝试将字符“±”设置为“名称”,但出现错误:
UnicodeDecodeError:“ascii”编解码器无法解码位置 0 的字节 0xb9:序数不在范围内(128)
如何解决这个问题?