5. Reference

pathvalidate.replace_symbol(text, replacement_text='')[source]

Replace all of the symbols.

Parameters:
  • text (str) – Input text.
  • replacement_text (str) – Replacement text.
Returns:

A replacement string.

Return type:

str

pathvalidate.sanitize_file_path(file_path, replacement_text='')[source]

Replace invalid characters for a file path within the file_path with the replacement_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 filename with the replacement_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_name with the replacement_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.

pathvalidate.validate_file_path(file_path)[source]
Parameters:filename (str) – File path to validate.
Raises:ValueError – If the file_path is empty or includes invalid char(s): \, :, *, ?, ", <, >, |.
pathvalidate.validate_filename(filename)[source]
Parameters:filename (str) – Filename to validate.
Raises:ValueError – If the filename is 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_name is a) empty. b) invalid as Python identifier. c) equals to reserved keywords or built-in constants.