PDA

View Full Version : [SOLVED] Python literal translation



jdb91
April 28th, 2011, 11:13 AM
Hi all, trying to get python to write a windows batch script (bear with me) with a path in . Easy enough, except it keeps using the \ (windows directory) as an exit sequence. In shell, to get round this, you use ' ' instead of " "

Is there anyway of doing this in python?

e.g.


>>> print '\bin'
in


I know the easiest thing to do is just backslash the backslashes, but that becomes very long winded.

jdb91
April 28th, 2011, 11:19 AM
Ah! got it



>>> print r'\bin'
\bin


Incase anyone else was wondering

StephenF
April 28th, 2011, 11:55 AM
Take a look at os.path.join() and os.path.sep.

andrew1992
April 28th, 2011, 07:25 PM
os.path.join/sep is the way to go for multi-platform. If you want a quick n dirty Windows solution, use the double backslash. '\\'