我仍然是 python 和 xml 的初学者。以下错误让我很困扰。以下是我在执行以下代码时得到的回溯混乱(错误):
Traceback (most recent call last):
File "path", line 66, in <module>
print slidename[a].childNodes[0].nodeValue
IndexError: list index out of range
从此代码:
for object in os.listdir(my_directory):
print (object)
if '.zip' in object:
#print (object)
new = os.path.splitext(object)
#print (new[0])
file_name.append(new[0])
os.mkdir(my_directory+new[0], 0o777)
with zipfile.ZipFile(my_directory+new[0]+new[1], "r") as z:
z.extractall(my_directory+new[0])
count = 0
for len_num in range(0,len(file_name)):
for doc in os.listdir(my_directory+file_name[len_num]+new_directory):
if '.xml' in doc:
#print doc
slide_name = os.path.splitext(doc)
#print slide_name
print ((file_name)[len_num])+'>>>'+((slide_name)[0])
file= xml.dom.minidom.parse(my_directory+((file_name)[len_num])+new_directory+doc)
tagname = file.getElementsByTagName('a:t')
#print tagname
for a in range(0,len(tagname)):
print tagname[a].childNodes[0].nodeValue
提前致谢!!