【发布时间】:2019-06-17 12:02:18
【问题描述】:
当我尝试解析子目录中的 xml 文件时,我得到一个 FileNotFoundError。当我将文件放在脚本旁边时,它可以很好地解析它。但为什么呢?
#!/usr/bin/env python3
import os
import xml.etree.ElementTree as ET
script_path = os.path.dirname(os.path.realpath(__file__))
path_to_file = os.path.join(script_path, '/test', 'file.xml')
# works
tree = ET.parse('file.xml')
# Throws file not found error
tree = ET.parse(path_to_file)
【问题讨论】:
-
从测试中删除 / 并尝试一下
标签: python xml parsing elementtree