4.4. Sanitize a filename

The sanitize_filename() function replace invalid character(s) for a filename within the argument.

Sample code
import pathvalidate

filename = "_a*b:c<d>e%f/(g)h+i_0.txt"
print(pathvalidate.sanitize_filename(filename))
Output
_abcde%f(g)h+i_0.txt

4.5. Sanitize a file path

The sanitize_file_path() function replace invalid character(s) for a file path within the argument.

Sample code
import pathvalidate

filename = "_a*b:c<d>e%f/(g)h+i_0.txt"
print(pathvalidate.sanitize_file_path(filename))
Output
_abcde%f/(g)h+i_0.txt

4.6. Sanitize a variable name

The sanitize_python_var_name() function replace invalid character(s) for a python variable within the argument.

Sample code
import pathvalidate

print(pathvalidate.sanitize_python_var_name("_a*b:c<d>e%f/(g)h+i_0.txt"))
Output
abcdefghi_0txt