go_from_altered_cwd
- pyhelpers.dirs.go_from_altered_cwd(dir_name, **kwargs)[source]
Get the full pathname of an altered working directory.
- Parameters:
dir_name (str | os.PathLike[str] | bytes | os.Path[bytes]) – name of a directory
kwargs – [optional] parameters of the function
pyhelpers.dirs.cd()
- Returns:
full pathname of an altered working directory (changed from the directory
path_to_dir
)- Return type:
str
Examples:
>>> from pyhelpers.dirs import go_from_altered_cwd >>> import os >>> init_cwd = os.getcwd() >>> init_cwd '<cwd>' >>> # Change the current working directory to "/new_cwd" >>> new_cwd = "\new_cwd" >>> os.mkdir(new_cwd) >>> os.chdir(new_cwd) >>> # Get the full path to a folder named "tests" >>> path_to_tests = go_from_altered_cwd(path_to_dir="tests") >>> path_to_tests '<new_cwd>\tests' >>> # Get the full path to a directory one level above the current working directory >>> path_to_tests_ = go_from_altered_cwd(path_to_dir="\tests") >>> path_to_tests_ == os.path.join(os.path.dirname(os.getcwd()), "tests") True >>> os.chdir(init_cwd) >>> os.rmdir(new_cwd)