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

时间:2017-06-13 10:25:42

标签: python

我的代码:

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(最近一次调用最后一次):文件   “C:\ Users \ HENRY \ Desktop \ prac1.py”,第6行,在树=中   ET.fromstring(open('C:/ Python27 / xml /'+ molstring +'。xml','r'))   IOError:[Errno 2]没有这样的文件或目录:   “C:/ Python27 / xml / set(['CID_11249995','CID_11249995'])。xml”

1 个答案:

答案 0 :(得分:0)

用于从多个xml文件中读取数据

mols = {'CID_11249995' , 'CID_11249995'}

for mol in mols:

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

     root = tree.getroot( )   

     print(root)