Skip to content

Commit

Permalink
Convert fp to a string (file name) when fp is not a file object
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Jul 20, 2019
1 parent 4b8e060 commit c5e115a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions jupytext/jupytext.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ def read(fp, as_version=4, fmt=None, **kwargs):
return reads(text, fmt)

if not hasattr(fp, 'read'):
_, ext = os.path.splitext(str(fp))
# Treat fp as a file name
fp = str(fp)
_, ext = os.path.splitext(fp)
fmt = copy(fmt or {})
fmt.update({'extension': ext})
with io.open(fp, encoding='utf-8') as stream:
Expand Down Expand Up @@ -315,9 +317,10 @@ def write(nb, fp, version=nbformat.NO_CONVERT, fmt=None, **kwargs):
return

if not hasattr(fp, 'write'):
fmt = copy(fmt or {})
# Treat fp as a file name
fp = str(fp)
_, ext = os.path.splitext(fp)
fmt = copy(fmt or {})
fmt = long_form_one_format(fmt, update={'extension': ext})
create_prefix_dir(fp, fmt)

Expand Down

0 comments on commit c5e115a

Please sign in to comment.