Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding on Windows #20

Merged
merged 3 commits into from
Sep 4, 2022
Merged

Fix encoding on Windows #20

merged 3 commits into from
Sep 4, 2022

Conversation

hugovk
Copy link
Collaborator

@hugovk hugovk commented Sep 4, 2022

Fixes #19, same thing as tkrajina/gpxpy#178 (comment).

This also adds an emoji to one of the test files, which before the fix fails on the CI on Windows (but not macOS or Linux): https://github.com/hugovk/strava_py/actions/runs/2987678688

After the fix, all pass.


Also use a "context manager" to open the file, instead of:

activity = gpxpy.parse(open(gpxfile, encoding="utf-8"))

Do this:

    with open(gpxfile, encoding="utf-8") as f:
        activity = gpxpy.parse(f)

A context manager takes care of closing file handles in case of errors, and is equivalent to

f = open(gpxfile, encoding="utf-8")
try:
    activity = gpxpy.parse(f)
finally:
    file.close()  # this runs no matter what happens

More info: https://towardsdatascience.com/why-you-should-use-context-managers-in-python-4f10fe231206

@hugovk hugovk added the bug Something isn't working label Sep 4, 2022
@marcusvolz marcusvolz merged commit 2b66523 into marcusvolz:main Sep 4, 2022
@hugovk hugovk deleted the fix-encoding branch September 4, 2022 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 379: character maps to <undefined>
2 participants