Forward slash or backslash?

Using forward slashes will make it system independent. I’d stick to that for simplicity. Consider using java.io.File.separator if you ever display the path to the user. You’d rather not surprise those Windows users. They’re a jumpy lot.

Python Replace \\ with \ [duplicate]

There’s no need to use replace for this. What you have is a encoded string (using the string_escape encoding) and you want to decode it: >>> s = r”Escaped\nNewline” >>> print s Escaped\nNewline >>> s.decode(‘string_escape’) ‘Escaped\nNewline’ >>> print s.decode(‘string_escape’) Escaped Newline >>> “a\\nb”.decode(‘string_escape’) ‘a\nb’ In Python 3: >>> import codecs >>> codecs.decode(‘\\n\\x21’, ‘unicode_escape’) ‘\n!’