5. Reference¶
-
pathvalidate.sanitize_file_path(file_path, replacement_text='')[source]¶ Replace invalid characters for a file path within the
file_pathwith thereplacement_text. Invalid characters are as follows:\,:,*,?,",<,>,|.Parameters: - file_path (str) – File path to sanitize.
- replacement_text (str) – Replacement text.
Returns: A replacement string.
Return type: str
-
pathvalidate.sanitize_filename(filename, replacement_text='')[source]¶ Replace invalid characters for a filename within the
filenamewith thereplacement_text. Invalid characters are as follows:\,:,*,?,",<,>,|,/.Parameters: - filename (str) – Filename to sanitize.
- replacement_text (str) – Replacement text.
Returns: A replacement string.
Return type: str
-
pathvalidate.sanitize_python_var_name(var_name, replacement_text='')[source]¶ Replace invalid characters for a Python variable name within the
var_namewith thereplacement_text. Invalid chars of the beginning of the variable name will be deleted.Parameters: - filename (str) – Name to sanitize.
- replacement_text (str) – Replacement text.
Returns: A replacement string.
Return type: str
Raises: ValueError – If the replacement string is invalid.
See also
-
pathvalidate.validate_file_path(file_path)[source]¶ Parameters: filename (str) – File path to validate. Raises: ValueError – If the file_pathis empty or includes invalid char(s):\,:,*,?,",<,>,|.
-
pathvalidate.validate_filename(filename)[source]¶ Parameters: filename (str) – Filename to validate. Raises: ValueError – If the filenameis empty or includes invalid char(s):\,:,*,?,",<,>,|,/.
-
pathvalidate.validate_python_var_name(var_name)[source]¶ Parameters: var_name (str) – Name to validate. Raises: ValueError – If the var_nameis a) empty. b) invalid as Python identifier. c) equals to reserved keywords or built-in constants.