python - 如何使用 sublime 3 创建要在 Python 中读取的 XML 文件?
问题描述
我正在 MTurk 中创建资格测试,为此我将为问题创建两个 .xml 文件,另一个用于评估工作人员的答案。我已经根据 AWS 的架构创建了文件,但是当我将 .xml 文件传递给 python 读取时,输出是找不到文件。
我不确定我错过了什么。
questions = open(name='question_form.xml', mode='r').read() #passing qual questions
answers = open(name='answerkey.xml', mode='r').read() #passing answerkey
解决方案
您是否尝试过使用 xml 包?:
with open('test.xml') as file_to_read:
root = ET.parse(file_to_read).getroot()
try :
print(root)
except :
print("could not retrieve value")
推荐阅读
- css - FontLoader 不工作 - 没有字体被加载
- javascript - PaperJS 画布绘图区域仅在左上角,除非采取外部操作
- alexa - 是否可以在不设置 AWS 配置文件的情况下设置 ASK CLI 配置文件
- android - Dropzone 在 Xamarin.Form 中不起作用。和安卓
- sql - 如何在sql中识别表包含默认和检查约束?
- python - 路径不能包含斜杠
- angular - 从模板中使用的第三方指令中捕获异常
- python-3.x - python3脚本在scrapy更新后停止工作
- python - 将十六进制字符串或字节数组转换为整数
- wordpress - Wordpress 添加模板不加载模板