首页 > 解决方案 > 如何使用 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

标签: pythonxmlamazon-web-servicessublimetext3

解决方案


您是否尝试过使用 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")

推荐阅读