5. Reference¶
-
pathvalidate.sanitize_filename(filename, replacement_text='')[source]¶ Replace invalid characters for a file path within the
filenamewith thereplacement_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_namewith thereplacement_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.
See also
-
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]¶ Replace invalid characters for a python variable name within the
var_namewith thereplacement_text. Invalid characters are as follows:\,:,*,?,",<,>,|.",!,#,$,&,',=,~,^,@,`,[,],+,-,;,{,},,,.,(,),%.Parameters: var_name (str) – Variable name to validate. Raises: ValueError – If a) the var_nameis empty. b) includes invalid char(s):\,:,*,?,",<,>,|. c)var_nameis start from digits or symbols (except"_").