How to remove bad path characters in Python?
I think the safest approach here is to just replace any suspicious characters. So, I think you can just replace (or get rid of) anything that isn’t alphanumeric, -, _, a space, or a period. And here’s how you do that: import re re.sub(r'[^\w_. -]’, ‘_’, filename) The above escapes every character that’s not a … Read more