【发布时间】:2013-04-14 09:35:20
【问题描述】:
对于我的项目,我需要解析 xml 文件。为此,我使用 lxml。我需要解析的文件有一个 cp1251 编码,但是,当然,为了使用 lxml 解析它,我需要将它解码为 utf-8,我不知道该怎么做。我试图对此进行搜索,但所有解决方案都适用于 Python 2.7 或不起作用。 如果尝试写类似
inp = open("business.xml", "r", encoding='cp1251').decode('utf-8')
或
inp.decode('utf-8')
得到
builtins.AttributeError: '_io.TextIOWrapper' object has no attribute 'decode'
我有 Python 3.2。 任何帮助都很好, 谢谢你。
【问题讨论】:
标签: python xml python-3.x decoding