0

I've been using this script (Merge multiple XML files from command line) to combine xml files on Debian Jessie. I'm in the process of moving to a dedicated server running CENTOS 6.6 x86_64. I'm having issues getting the script to work in the new environment. Any Help would be appreciated.

python version 2.7

THE SCRIPT

#!/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
Community
  • 1
  • 1
Pop
  • 57
  • 1
  • 8

1 Answers1

1

This error can be caused by using of python2.6, because extend appears only in python 2.7. Are you sure that you use python 2.7? Can you, please, run

python --version

?

It can be that the default version of python in your system is 2.6 and you need to specify the right one instead of

#!/usr/bin/env python
Viorel Roman
  • 120
  • 2
  • Thanks, I got it figured out. I had the xmlcombine.py set to call python2.7 but not the main script. shopt -s extglob for f in $PATH_VAR/*; do [ -d $f ] && cd "$f" && python27 $SCRIPT/xmlcombine.py !(combined).xml > "$f"-combined.xml; done; – Pop Sep 03 '15 at 16:26