I'm a new comer about python, and I code this program to deal with xml in os.walk(). This program can print "channel code" from different xml files, and they all named "mmiap.xml".
It is the code:
#coding=utf-8
import os
import xml.dom.minidom
path = "H:\\Dev\\CODE\\MMwithwalk\\"
for root, dirs,files in os.walk(path):
dom = xml.dom.minidom.parse('mmiap.xml')
root = dom.documentElement
bb = root.getElementsByTagName('channel') #Get channel code from mmiap.xml
b= bb[0]
print (b.firstChild.data)
After run this program, it shows "FileNotFoundError: [Errno 2] No such file or directory: 'mmiap.xml'"
What's wrong? It seems that traversal is not walk depth. But I can't find the problem.
PS: If I drag a mmiap.xml to root directory, channel code will be printed normally.
Aucun commentaire:
Enregistrer un commentaire