Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python &引用;实例没有属性';国际热核实验堆&x27&引用;不能从命令行工作_Python_Xml_Elementtree - Fatal编程技术网

Python &引用;实例没有属性';国际热核实验堆&x27&引用;不能从命令行工作

Python &引用;实例没有属性';国际热核实验堆&x27&引用;不能从命令行工作,python,xml,elementtree,Python,Xml,Elementtree,我最近开始使用Python编辑XML,但我仍然觉得这很棘手 现在我完成了我的脚本并首先手动测试了它。成功了。 然后我尝试完全运行脚本,但收到了一个以前没有发生过的错误 我在这里提供了一个简单的例子: import glob import os import sys import xml.etree.ElementTree as ET curgraph = "somefolder/somefolder/editedGraphPath_full.xml" tree = ET.parse(cu

我最近开始使用Python编辑XML,但我仍然觉得这很棘手

现在我完成了我的脚本并首先手动测试了它。成功了。 然后我尝试完全运行脚本,但收到了一个以前没有发生过的错误

我在这里提供了一个简单的例子:

import glob
import os
import sys
import xml.etree.ElementTree as ET

curgraph = "somefolder/somefolder/editedGraphPath_full.xml"   
tree = ET.parse(curgraph)
root = tree.getroot()
i=0
for file in root.iter('file'):
  i = i+1
  print i
如果我在Python中一行一行地运行这个程序,那么一切都很好。但是,如果在cmd行上运行它,则会出现以下错误:

Traceback (most recent call last):
  File "/somefolder/somefolder/test.py", line 12, in <module>
    for file in root.iter('file'):
AttributeError: _ElementInterface instance has no attribute 'iter'
回溯(最近一次呼叫最后一次):
文件“/somefolder/somefolder/test.py”,第12行,在
对于root.iter(“文件”)中的文件:
AttributeError:_ElementInterface实例没有属性“iter”
我试着用一些相关的问题和SO,但我还没有发现任何有用的东西。

使用
root.findall(…)


但这并不是递归地搜索XML的所有子节点,对吗?它实际上是有效的,但需要定义文件节点在XML结构中的确切位置。我研究了国际热核实验堆(iter),以便不受结构知识的影响
import glob
import os
import sys
import xml.etree.ElementTree as ET

curgraph = "somefolder/somefolder/editedGraphPath_full.xml"   
tree = ET.parse(curgraph)
root = tree.getroot()
i=0
for file in root.findall('file'):
  i = i+1
  print i