cd_data

pyhelpers.dirs.cd_data(*subdir, data_dir='data', mkdir=False, normalized=True, **kwargs)[source]

Specifies the pathname of a directory (or file) under data_dir of a package.

Parameters:
  • subdir (str | os.PathLike | bytes) – Name of a directory or directories (and/or a filename).

  • data_dir (str | 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.

  • normalized (bool) – Whether to normalize the returned pathname; defaults to True.

  • 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)  # on Windows
'pyhelpers\data\tests'