_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=' ... ', print_wrap_limit=None, belated=False, 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
endparameter ofprint; defaults to" ... ".print_wrap_limit (int | None) – Maximum length of the string before splitting into two lines; defaults to
None, which disables splitting. If the string exceeds this value, e.g.100, it will be split at (before)state_prepto improve readability when printed.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" in "./tests/documents/" ... Passed. >>> _check_saving_path(path_to_file, verbose=True, print_wrap_limit=10); print("Passed.") Updating "pyhelpers.pdf" ... in "./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.