[Tutor] Single Backslash (was 'DOS Commands?')

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Fri Nov 8 11:46:21 2002


On Fri, 8 Nov 2002 James.Rocks@equant.com wrote:

> Hi Magnus,
>
> > os.popen('ls -l').readlines()
>
> Yes, that works thanks ... now if I could only figure how to make a string
> with a single backslash I should be sorted!


Hi James,


Here you go:

###
>>> title = '// This is a test \\\\'
>>> print title
// This is a test \\
###

Whenever we want literal backslashes, we need to double them up.  The
sequence '\\' will tell Python that we really do mean to put a literal
backslash in our string.


Good luck to you!