Skip to content

Commit c0199f6

Browse files
committed
nbdev-export python files
1 parent 8d76bc2 commit c0199f6

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

fastcore/_modidx.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,11 @@
704704
'fastcore.xtras.Path.mk_write': ('xtras.html#path.mk_write', 'fastcore/xtras.py'),
705705
'fastcore.xtras.Path.normpath': ('xtras.html#path.normpath', 'fastcore/xtras.py'),
706706
'fastcore.xtras.Path.read_json': ('xtras.html#path.read_json', 'fastcore/xtras.py'),
707+
'fastcore.xtras.Path.read_yml': ('xtras.html#path.read_yml', 'fastcore/xtras.py'),
707708
'fastcore.xtras.Path.readlines': ('xtras.html#path.readlines', 'fastcore/xtras.py'),
708709
'fastcore.xtras.Path.relpath': ('xtras.html#path.relpath', 'fastcore/xtras.py'),
709710
'fastcore.xtras.Path.write_json': ('xtras.html#path.write_json', 'fastcore/xtras.py'),
711+
'fastcore.xtras.Path.write_yml': ('xtras.html#path.write_yml', 'fastcore/xtras.py'),
710712
'fastcore.xtras.ReindexCollection': ('xtras.html#reindexcollection', 'fastcore/xtras.py'),
711713
'fastcore.xtras.ReindexCollection.__getitem__': ( 'xtras.html#reindexcollection.__getitem__',
712714
'fastcore/xtras.py'),

fastcore/xtras.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,14 @@ def read_json(self:Path, encoding=None, errors=None):
433433
"Same as `read_text` followed by `loads`"
434434
return loads(self.read_text(encoding=encoding, errors=errors))
435435

436+
# %% ../nbs/03_xtras.ipynb #6c5f7de3
437+
@patch
438+
def read_yml(self:Path, encoding=None, errors=None):
439+
"Same as `read_text` followed by `yaml.safe_load`"
440+
try: import yaml
441+
except ImportError: raise ImportError("pip install pyyaml")
442+
return yaml.safe_load(self.read_text(encoding=encoding, errors=errors))
443+
436444
# %% ../nbs/03_xtras.ipynb #d6d8d893
437445
@patch
438446
def mk_write(self:Path, data, encoding=None, errors=None, mode=511, uid=-1, gid=-1):
@@ -447,6 +455,14 @@ def write_json(self:Path, data, encoding=None, errors=None, mode=511, uid=-1, gi
447455
"Same as `dumps`followed by `mk_write`"
448456
self.mk_write(dumps(data,**kw),encoding,errors,mode,uid,gid)
449457

458+
# %% ../nbs/03_xtras.ipynb #0290ae06
459+
@patch
460+
def write_yml(self:Path, data, encoding=None, errors=None, mode=511, uid=-1, gid=-1, **kw):
461+
"Same as `yaml.dump` followed by `mk_write`"
462+
try: import yaml
463+
except ImportError: raise ImportError("pip install pyyaml")
464+
self.mk_write(yaml.dump(data, **kw), encoding, errors, mode, uid, gid)
465+
450466
# %% ../nbs/03_xtras.ipynb #9fc9965f
451467
@patch
452468
def relpath(self:Path, start=None):

0 commit comments

Comments
 (0)