0
我一直在使用此腳本(Merge multiple XML files from command line)在Debian Jessie上合併xml文件。我正在轉向運行CENTOS 6.6 x86_64的專用服務器。我有問題讓腳本在新環境中工作。任何幫助,將不勝感激。合併多個XML文件
蟒版本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:])
THE ERRORS
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
謝謝,我想通了。我將xmlcombine.py設置爲調用python2.7,但不是主腳本。 \t shopt -s extglob \t for $ $ PATH_VAR/*; \t do \t [-d $ f] && cd「$ f」&& python27 $ SCRIPT/xmlcombine.py!(combined).xml>「$ f」-combined.xml; \t完成; – Pop