저는이 스크립트 ( Merge multiple XML files from command line )를 사용하여 Debian Jessie에서 xml 파일을 결합했습니다. CENTOS 6.6 x86_64를 실행하는 전용 서버로 이동하는 중입니다. 새 환경에서 스크립트가 작동하도록하는 데 문제가 있습니다. 어떤 도움을 주시면 감사하겠습니다.
파이썬 버전 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
이 오류는 extend가 python 2.7에서만 나타나기 때문에 python2.6을 사용하여 발생할 수 있습니다. python 2.7을 사용하고 있습니까? 제발 달려 줄래
python --version
?
시스템의 기본 Python 버전이 2.6이고 대신 올바른 버전을 지정해야 할 수 있습니다.
#!/usr/bin/env python
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다