_check_saving_path

pyhelpers.store._check_saving_path(path_to_file, verbose=False, print_prefix='', state_verb='Saving', state_prep='to', print_suffix='', print_end=' ... ', ret_info=False)[source]

Verifies a specified file path before saving.

Parameters:
  • path_to_file (str | pathlib.Path) – Path where the file will be saved.

  • verbose (bool | int) – Whether to print relevant information to the console; defaults to False.

  • print_prefix (str) – Text prefixed to the default print message; defaults to "".

  • state_verb (str) – Verb indicating the action being performed, e.g. saving or updating; defaults to "Saving".

  • state_prep (str) – Preposition associated with state_verb; defaults to "to".

  • print_suffix (str) – Text suffixed to the default print message; defaults to "".

  • print_end (str) – String passed to the end parameter of print; defaults to " ... ".

  • ret_info (bool) – Whether to return file path information; defaults to False.

Returns:

A tuple containing the relative path and, if ret_info=True, the filename.

Return type:

tuple

Tests:

>>> from pyhelpers.store import _check_saving_path
>>> from pyhelpers.dirs import cd
>>> path_to_file = cd()
>>> _check_saving_path(path_to_file, verbose=True)
Traceback (most recent call last):
    ...
AssertionError: The input for `path_to_file` may not be a file path.
>>> path_to_file = "pyhelpers.pdf"
>>> _check_saving_path(path_to_file, verbose=True); print("Passed.")
Saving "pyhelpers.pdf" ... Passed.
>>> path_to_file = cd("tests", "documents", "pyhelpers.pdf")
>>> _check_saving_path(path_to_file, verbose=True); print("Passed.")
Saving "pyhelpers.pdf" to ".\tests\documents\" ... Passed.
>>> path_to_file = "C:\Windows\pyhelpers.pdf"
>>> _check_saving_path(path_to_file, verbose=True); print("Passed.")
Saving "pyhelpers.pdf" to "C:\Windows\" ... Passed.
>>> path_to_file = "C:\pyhelpers.pdf"
>>> _check_saving_path(path_to_file, verbose=True); print("Passed.")
Saving "pyhelpers.pdf" to "C:\" ... Passed.