[英]Merge multiple XML files
我一直在使用此脚本( 从命令行合并多个XML文件 )来在Debian Jessie上合并xml文件。 我正在迁移到运行CENTOS 6.6 x86_64的专用服务器。 我在使脚本在新环境中运行时遇到问题。 任何帮助,将不胜感激。
python版本2.7
剧本
#!/usr/bin/env python
import sys
from xml.etree import ElementTree
def run(files):
first = None
for filename in files:
data = ElementTree.parse(filename).getroot()
if first is None:
first = data
else:
first.extend(data)
if first is not None:
print ElementTree.tostring(first)
if __name__ == "__main__":
run(sys.argv[1:])
错误
0+0 records in
0+0 records out
0 bytes (0 B) copied, 9.8139e-05 s, 0.0 kB/s
0+0 records in
0+0 records out
0 bytes (0 B) copied, 7.7816e-05 s, 0.0 kB/s
0+0 records in
0+0 records out
0 bytes (0 B) copied, 7.3015e-05 s, 0.0 kB/s
0+0 records in
0+0 records out
0 bytes (0 B) copied, 7.1727e-05 s, 0.0 kB/s
0+0 records in
0+0 records out
0 bytes (0 B) copied, 7.6014e-05 s, 0.0 kB/s
0+0 records in
0+0 records out
0 bytes (0 B) copied, 8.1163e-05 s, 0.0 kB/s
Traceback (most recent call last):
File "/location/private/xmlcombine.py", line 17, in <module>
run(sys.argv[1:])
File "/location/private/xmlcombine.py", line 12, in run
first.extend(data)
AttributeError: _ElementInterface instance has no attribute 'extend'
Traceback (most recent call last):
File "/location/private/xmlcombine.py", line 17, in <module>
run(sys.argv[1:])
File "/location/private/xmlcombine.py", line 12, in run
first.extend(data)
AttributeError: _ElementInterface instance has no attribute 'extend'
Traceback (most recent call last):
File "/location/private/xmlcombine.py", line 17, in <module>
run(sys.argv[1:])
File "/location/private/xmlcombine.py", line 12, in run
first.extend(data)
AttributeError: _ElementInterface instance has no attribute 'extend'
Process Completed
此错误可能是由于使用python2.6引起的,因为extend仅出现在python 2.7中。 您确定使用python 2.7吗? 你能跑吗
python --version
?
可能是系统中python的默认版本是2.6,而您需要指定正确的版本而不是
#!/usr/bin/env python
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.