Python 3 issue - 'filter' object has no attribute 'sort'
BjGoCraft opened this issue · comments
When I try to execute the script with Python 3.10.6 I get the error message
'filter' object has no attribute 'sort'
I found this other issue that points out changes in python 3 that caused this issue:
raghakot/keras-text#9
But I'm new to python and can't fix this/propose a solution. Would be glad if you'd update your project :)
I found a fix for that. You are probably merging gpx files without timestamps. You can comment lines 47 and 49 and it will work.
# 2. Remove trkpts without timestamp
track_segment = filter(lambda trkpt: trkpt.time is not None, track_segment)
# 3. Sort trkpts chronologically
track_segment.sort(key=lambda trkpt: trkpt.time)
By now I learned python and wrote my own python script for my use case :D
Nevertheless I tried your fix. It kinda worked. I don't get the error anymore and I get usable gpx data except when using gpx-tracks recorded with OsmAND. They can't be opened by any program. Their trackpoints look like this:
<trkpt lat="9.5520863" lon="49.6756989">
<ele>16.9</ele>
<time>2023-05-20T12:43:19Z</time>
<hdop>3.9</hdop>
<extensions>
<osmand:bearing>14.8</osmand:bearing>
<osmand:speed>9.6</osmand:speed>
<osmand:heading>0</osmand:heading>
</extensions>
</trkpt>
Maybe it has something to do with the 'osmand' in the extension's name, I don't know. But this is an edge case I don't want to spend more time with since my script only uses the coordinate part of the trackpoints. Also I don't understand why commenting these lines worked since all my gpx files do have timestamps.
Anyway thanks for the help :)