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.PathLike[bytes]) – Name of a directory or directories (and/or a filename).

  • data_dir (str | os.PathLike[str] | bytes | os.PathLike[bytes]) – Name of the directory to store data; defaults to "data".

  • mkdir (bool) – Whether to create the directory if it does not exist; defaults to False.

  • kwargs – [Optional] Additional parameters (e.g. mode=0o777) for the function os.makedirs.

Returns:

Pathname of a directory or 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'