I have few python scripts which were written by someone else in Windows. These scripts use double backslash as path separator but when run in Ubuntu they don't work because of this. I can change all \ to / and scripts will work but there are lot of scripts and its a lot of effort to change each \ to /
So my question is: Is it possible to add \ as path separator in Ubuntu or only in Bash so that I dont have to modify these scripts?
Example code:
# Append Common directory to the Python search path
sys.path.append('..\\..\\..' + os.sep + 'Common')
In Linux, filenames can contain any characters except
/
(since it's the path separator) and the NUL byte (the string terminator,\0
). That means\
is a valid character in a filename, as well as newlines, tabs, terminal escape sequences, unprintable characters... so no, you can't temporarily use\
as a path separator.Windows is not as liberal, and has a larger set of characters not allowed in filenames, and
/
is one of those characters not allowed. For this reason, python will also consider/
a path separator on Windows, so changing those\\
to/
should make the script work on both Windows and Ubuntu. That said, the proper way to join paths in python is to use the os.path.join function.I recommend going through the scripts and manually fix all the non-portable code.
I cannot answer you question, but it is very easy to change \ to / in all scripts like this:
(Just try it on a copy of your files first!)