关于python:IOError:[Errno 2]没有来自多个xml文件的此类文件或目录

IOError: [Errno 2] No such file or directory from multiple xml files

我的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import xml.etree.ElementTree as ET
import sys

XS = '{http://pubchem.ncbi.nlm.nih.gov/pug_view}'

mols = {'CID_11249995','CID_11249995'}

molstring = str(mols);

tree = ET.fromstring(open('C:/Python27/xml/'+ molstring +'.xml','r'))

root = tree.getroot( )

print(root)

这会产生以下错误:

Traceback (most recent call last): File
"C:\Users\HENRY\Desktop\prac1.py", line 6, in tree =
ET.fromstring(open('C:/Python27/xml/'+ molstring +'.xml','r'))
IOError: [Errno 2] No such file or directory:
"C:/Python27/xml/set(['CID_11249995', 'CID_11249995']).xml"


用于从多个XML文件读取数据

1
2
3
4
5
6
7
8
9
mols = {'CID_11249995' , 'CID_11249995'}

for mol in mols:

     tree = ET.parse('tree path' + mol + '.xml')

     root = tree.getroot( )  

     print(root)