GPXPY Library – Can It Write GPX File? Detailed Explanation

gpxpython

I want to build a .gpx file and was hoping to use gpxpy. I can see how to build such a file in memory, but I can't see how to write it out to disk.

Is it possible for gpxpy to write files?

Best Answer

With gpxpy no, but with simple Python yes

Using the example of the PyPi page

....
print('Created GPX:', gpx.to_xml())
with open("output.gpx", "w") as f:
    f.write( gpx.to_xml())

(gpxpy uses lxml or elementtree to parse .gpx files (in parser.py file))