Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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')
share|improve this question

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.

share|improve this answer

I cannot answer you question, but it is very easy to change \ to / in all scripts like this:

find <root_of_scripts> -name "*.py" -exec sed -i 's/\\\\/\//g' {} \;

(Just try it on a copy of your files first!)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.