Quantcast
Channel: User David Z - Stack Overflow
Viewing all articles
Browse latest Browse all 49

Answer by David Z for How can I put an actual backslash in a string literal (not use it for an escape sequence)?

$
0
0

To answer your question directly, put r in front of the string.

final= path + r'\xulrunner.exe '+ path + r'\application.ini'

More on Python's site here

Both string and bytes literals may optionally be prefixed with a letter 'r' or 'R'; such strings are called raw strings and treat backslashes as literal characters

But a better solution would be os.path.join:

final = os.path.join(path, 'xulrunner.exe') +''+ \         os.path.join(path, 'application.ini')

(the backslash there is escaping a newline, but you could put the whole thing on one line if you want)

I will mention that you can use forward slashes in file paths, and Python will automatically convert them to the correct separator (backslash on Windows) as necessary. So

final = path +'/xulrunner.exe '+ path +'/application.ini'

should work. But it's still preferable to use os.path.join because that makes it clear what you're trying to do.


Viewing all articles
Browse latest Browse all 49

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>