def save(self): # create gpx document from existing gpx file today = datetime.date.today().strftime("%Y-%m-%d") gpx_file = os.path.join(self.directory, today + '.xml') document = Document(children=[], name=today) if os.path.exists(gpx_file): document = document.readGPX(gpx_file) # add track to document segment = TrackSegment(points=self.track_points) document.append(Track(segments=[segment])) # add way points to document for wp in self.way_points: document.append(wp) # write or overwrite gpx file f = open(gpx_file, "wb") f.write(document.toGPX().toprettyxml(encoding="utf-8")) f.close() self.track_points = [] self.way_points = []