import argparse import xml.etree.ElementTree as cars_Etree # elementTree not reading xml file properly if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument( dest='file_name', action='store', help='File name', metavar='FILE' ) parser.add_argument( 'car_make', help='car name') args = parser.parse_args() with open(args.file_name, 'r') as cars_file: vehicles = cars_Etree.parse(cars_file) cars = vehicles.getroot() for make in cars.findall(args.car_make): name = make.get('name') if name != args.car_make: cars.remove(make) with open(args.file_name, 'w') as cars_file: vehicles.write(cars_file) Error:
Traceback (most recent call last): File "/Users/benbitdiddle/PycharmProjects/VehicleFilter/FilterTest.py", line 23, in <module> vehicles = cars_Etree.parse(cars_file) File "/Applications/anaconda/lib/python3.5/xml/etree/ElementTree.py", line 1184, in parse tree.parse(source, parser) File "/Applications/anaconda/lib/python3.5/xml/etree/ElementTree.py", line 596, in parse self._root = parser._parse_whole(source) xml.etree.ElementTree.ParseError: syntax error: line 1, column 0
No comments:
Post a Comment