As we know, windows accept both "\" and "/" as separator.
But in python, "\" is used. For example, call os.path.join("foo","bar"), 'foo\\bar' will be returned. What’s annoying is that there’s an escape character, so you cannot just copy the path string and paste to your explorer location bar.
I wonder is there any way to make python use "/" as default separator, I’ve tried change the value of os.path.sep and os.sep to "/", but os.path.join still use "\\".
what’s the right way?
PS:
I just don’t understand why python is using “\” as default separator on windows, maybe old version of windows don’t support “/”?
Why not define a custom display function?
e.g.
And if you want to substitute
str.joinforos.path.join, you can just do this (str.joinexpects a single list,os.path.joinexpects*args):Perhaps better would be to let Python normalize everything, then replace, e.g.:
The only issue with the above might be on posix when there is a space in the file path.
You could then put an
ifstatement at the top of your utils file and definedisplay_pathandjoinas a no-op and as os.path.join respectively if not on Windows.