cd_data
- pyhelpers.dirs.cd_data(*subdir, data_dir='data', mkdir=False, **kwargs)[source]
Get the full pathname of a directory (or file) under
data_dir
of a package.- Parameters:
subdir (str | os.PathLike[str] | bytes | os.Path[bytes]) – name of directory or names of directories (and/or a filename)
data_dir (str | os.PathLike[str] | bytes | os.Path[bytes]) – name of a directory to store data, defaults to
"data"
mkdir (bool) – whether to create a directory, defaults to
False
kwargs – [optional] parameters (e.g.
mode=0o777
) of os.makedirs
- Returns:
full pathname of a directory or that of a file under
data_dir
of a package- Return type:
str
Examples:
>>> from pyhelpers.dirs import cd_data >>> import os >>> path_to_dat_dir = cd_data("tests", mkdir=False) >>> os.path.relpath(path_to_dat_dir) 'pyhelpers\data\tests'