mixed slashes with os.path.join on windows

You can use .replace() after path.join() to ensure the slashes are correct:

# .replace() all backslashes with forwardslashes
print os.path.join(a, b, c, d, e).replace("\\","https://stackoverflow.com/")

This gives the output:

c:/myFirstDirectory/mySecondDirectory/myThirdDirectory/myExecutable.exe

As @sharpcloud suggested, it would be better to remove the slashes from your input strings, however this is an alternative.

Leave a Comment

tech