我知道这个问题在堆栈上已被多次询问(并回答)。而且我已经尝试了很多,但由于某种原因我无法克服这个错误:
Traceback (most recent call last):
File "J:\eclipse\workspace_python\TF2_Monitor\src\TF2_Monitor.py", line 23, in <module>
xmldoc = minidom.parse(sampleXML)
File "C:\Python27\lib\xml\dom\minidom.py", line 1920, in parse
return expatbuilder.parse(file)
File "C:\Python27\lib\xml\dom\expatbuilder.py", line 922, in parse
fp = open(file, 'rb')
IOError: [Errno 2] No such file or directory: '<?xml version = "1.0" encoding = "utf-8"?>\n<Patients>\n <Patient>\n <PatientCharacteristics>\n <patientCode>3</patientCode>\n </PatientCharacteristics>\n </Patient>\n</Patients>'
这是导致问题的代码位:-
if __name__ == '__main__':
from xml.dom import minidom
sampleXML = """<?xml version = "1.0" encoding = "utf-8"?>
<Patients>
<Patient>
<PatientCharacteristics>
<patientCode>3</patientCode>
</PatientCharacteristics>
</Patient>
</Patients>"""
xmldoc = minidom.parse(sampleXML)
从以前的答案“没有这样的文件目录”意味着它找不到 xml,但是当我在代码中将它声明为变量时,情况仍然如此吗?我猜这很简单,但就是找不到。