smpl_io.io.pushd

smpl_io.io.pushd(new_dir, tmp=False, cd=True)[source]

Move to a new directory and return to the previous one after context.

Parameters

new_dirstr

new directory.

tmp: bool, optional

create the directory if it does not exist and delete after context, by default False

cd: bool, optional

change to (new) directory, by default True

Examples

>>> import os
>>> p = os.getcwd()
>>> with pushd("tmptest",tmp=True):
...     pp = os.getcwd()
...     pp.startswith(p) and pp.endswith("tmptest")
True
>>> import os
>>> p = os.getcwd()
>>> with pushd("tmptest",tmp=True,):
...     pp = os.getcwd()
...     pp.startswith(p) and pp.endswith("tmptest")
True