Edited question: I am writing a python function that takes the string of a path as copy-pasted from windows (so with backslashes) and returns a string with forwardslashes, that can be used by python as a path. The problem arises with the combination of backlashes and other characters, like \n, \b... Thanks to Coldspeed, I now have a function that sort of does the trick:
def back2forwardSlash(backSlash_string):
return backSlash_string.replace('\\', '/')
What's still unsatisfactory is that I have to call the function with the r
before the string to read it as raw: fileNamePath = back2forwardSlash(r'C:\Users\Dropbox\netCFD4\b30.137.nc')
This prevents passing a variable into the function, instead of pasting in the string. Or at least, I don't think I have a solution to that.