5. Reference

pathvalidate.sanitize_filename(filename, replacement_text='')[source]

Replace invalid characters for a file path within the filename with the replacement_text. Invalid characters are as follows: \, :, *, ?, ", <, >, |.

Parameters:
  • filename (str) – Filename to validate.
  • 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 characters are as follows: \, :, *, ?, ", <, >, |. ", !, #, $, &, ', =, ~, ^, @, `, [, ], +, -, ;, {, }, ,, ., (, ), %.

Parameters:
  • filename (str) – Filename to validate.
  • replacement_text (str) – Replacement text.
Returns:

A replacement string.

Return type:

str

Raises:

ValueError – If the replacement string is invalid.

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]

Replace invalid characters for a python variable name within the var_name with the replacement_text. Invalid characters are as follows: \, :, *, ?, ", <, >, |. ", !, #, $, &, ', =, ~, ^, @, `, [, ], +, -, ;, {, }, ,, ., (, ), %.

Parameters:var_name (str) – Variable name to validate.
Raises:ValueError – If a) the var_name is empty. b) includes invalid char(s): \, :, *, ?, ", <, >, |. c) var_name is start from digits or symbols (except "_").