elementTree is not opening and parsing my xml file
<p>seems like <code>vehicles.write(cars_file)</code> and <code>vehicles = cars_Etree.parse(cars_file)</code> are having a problem with the file name:</p>

<pre><code>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)
</code></pre>

<p>Error:</p>

<pre><code>Traceback (most recent call last):
  File "/Users/benbitdiddle/PycharmProjects/VehicleFilter/FilterTest.py", line 23, in &lt;module&gt;
    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
</code></pre>

<p>XML file, which I am trying to filter, is in the same project folder. I tried supplying the path with the file name and it still didn't work.</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;cars&gt;
    &lt;make name="toyota"&gt;
        &lt;model name="tacoma" /&gt;
        &lt;model name="tundra" /&gt;
    &lt;/make&gt;
    &lt;make name="ford"&gt;
        &lt;model name="escort" /&gt;
        &lt;model name="taurus" /&gt;
    &lt;/make&gt;
    &lt;make name="chevy"&gt;
        &lt;model name="silverado" /&gt;
        &lt;model name="volt" /&gt;
    &lt;/make&gt;
&lt;/cars&gt;
</code></pre>

<p>works fine now but im still improving it. thank you    </p>

<p>I made this modification in main.py:</p>

<pre><code>path = "/Users/benbitdiddle/PycharmProjects/VehicleFilter/"
CF = CarFilter(path+args.file_name, args.car_make)
CF.filterCar()
</code></pre>

<p>And changed 'w' to wb' in CarFilter.py class file:</p>

<pre><code>    with open(self.file_name, 'wb') as car_file:
        self.vehicles.write(car_file)
</code></pre>

python xml argparse elementtree