python-3.x - 无法使用 python 从路径解析 XML 文件
问题描述
当我尝试解析与脚本不在同一目录中的 xml 文件时,出现此错误:
File "C:\Users\Yac\AppData\Local\Programs\Python\Python37\lib\xml\etree\ElementTree.py", line 1197, in parse
tree.parse(source, parser)
File "C:\Users\Yac\AppData\Local\Programs\Python\Python37\lib\xml\etree\ElementTree.py", line 598, in parse
self._root = parser._parse_whole(source)
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0
这是我的代码:
import xml.etree.ElementTree as ET
tree = ET.parse(r'C:\Users\Yac\Desktop\AAAAA\ABD\DATA.xml')
解决方案
尝试使用tree = ET.parse(“path/to/file.xml”)
或
ET.fromstring(open(‘path/to/file.xml’).read())
推荐阅读
- scala - 在Scala中将时间戳值转换为双精度值
- python - 带有 sqlalchemy db 连接的 Pytest 在后续测试用例中终止
- javascript - 在 GAS Web 编辑器中输入符号
- php - 如何使用 Doctrine 持久化引用自身的对象?
- web - Asp.net 形成应用程序-超时和丢失数据
- react-native - react-native:expo 将应用程序清单存储在公共域中
- python - 由于名称相同,箱线图重叠
- python - 如何将 tkinter 中的条目信息传输到列表
- javascript - 从 javascript 对象中删除属性
- botframework - luis 的话语与单词示例不被考虑