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

Pass string instead of Path object to open #37

Merged
merged 1 commit into from
Sep 20, 2019

Conversation

hankso
Copy link
Contributor

@hankso hankso commented Sep 20, 2019

What is the error

A path object cannot be directly opened like a filename string.

How to reproduce

>>> from pathlib import Path
>>> p = Path('xdf_sample.xdf')    # it's a path object
>>> open(Path('xdf_sample.xdf'))  # but open only accept str / bytes
TypeError: invalid file: PosixPath('xdf_sample.xdf')

Same as gzip.open

>>> import gzip
>>> gzip.open(Path('foo'))
TypeError: filename must be a str or bytes object, or a file

How to fix

>>> p = Path('foo')
>>> open(str(p))

BTW, I suggest NOT to mix using os.path and pathlib. So all os.path functions are replaced.

Please consider merging.

Python 3.5.2
Ubuntu 16.04

- Use only `pathlib.Path` and remove `os.path` functions.
- Open XDF with filename string instead of a path object.
@cboulay
Copy link
Contributor

cboulay commented Sep 20, 2019

This is a 3.5 backwards compatibility patch. In Python 3.6 and up, open accepts Pathlike objects.
It looks good to me. Thanks for the PR!

@cboulay cboulay merged commit 56552f9 into xdf-modules:master Sep 20, 2019
@cbrnr
Copy link
Contributor

cbrnr commented Sep 24, 2019

@hankso would you like your real name to be shown in the changelog for your contribution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants