sgraaf / gpx

A python package that brings support for reading, writing and converting GPX files.
https://gpx.readthedocs.io/en/stable/
Other
11 stars 3 forks source link

Readme contains incorrect example #20

Open larsks opened 2 weeks ago

larsks commented 2 weeks ago

This is mostly a duplicate of #19, which was erroneously closed.

The readme suggests we can use the GPX module like this:

>>> from gpx import Waypoint
>>>
>>> # delete the last waypoint
>>> del gpx.waypoints[-1]
>>>
>>> # add a new waypoint
>>> wpt = Waypoint()
>>> wpt.latitude = 52.123
>>> wpt.longitude = 4.123
>>> gpx.waypoints.append(wpt)

But doing so will eventually result in the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../.venv/lib/python3.12/site-packages/gpx/gpx.py", line 300, in to_string
    gpx = self._build()
          ^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/gpx/gpx.py", line 234, in _build
    gpx.append(_waypoint._build())
               ^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/gpx/waypoint.py", line 179, in _build
    waypoint.set("lat", str(self.lat))
                            ^^^^^^^^
AttributeError: 'Waypoint' object has no attribute 'lat'. Did you mean: 'sat'?

According to #19, this is because:

The actual property names for latitude and longitude are lat and lon, respectively. For reference, check out the API reference on the Waypoint object.

So we should update the README file to reflect the actual attribute names.

sgraaf commented 2 weeks ago

Hey again! Thank you for opening another issue... it wasn't clear to me that you hadn't just made a typo, but that instead the example given in the docs is outdated / wrong. You're right that the README (and anywhere else where applicable) should be updated (and perhaps doctested).