pythonpath

How to remove bad path characters in Python?


What is the most cross platform way of removing bad path characters (e.g. "" or ":" on Windows) in Python?


Solution

  • Unfortunately, the set of acceptable characters varies by OS and by filesystem.

    Your best bet is probably to either be overly-conservative on all platforms, or to just try creating the file name and handle errors.