backslashes in test =?iso-8859-1?Q?stringsR=FD=B0=3F=B6=3F=AE=FD=A9=3F=3F=3F=A6=FD=AF=7E=B3=B5=A4=FD=B7=3F=B7=3F=AD=24=ECn?=

Christian Tismer tismer at appliedbiometrics.com
Mon May 24 15:51:56 EDT 1999


chris_barker at my-dejanews.com wrote:
> 
> In article <020901bea522$b07a78c0$f29b12c2 at pythonware.com>,
> >
> > oops.  did you forget that \n is a newline?
> >
> > starting with Python 1.5.2, you can use os.spawnv:
> >
> > status = os.spawnv(os.P_WAIT, "c:\\ntreskit\\sc", ("stop", serviceA))
> > (untested)
> >
> 
> There is a much niftyier way to dealk with the backslash problem. Use
> Python's "raw" strings: ie:
> status = os.spawn(os.P_WAIT, r"c:=netreskit\sc",("stop", serviceA))
> 
> prepending an r to a string tells python that it is a "raw" string, snd
> that it shouldn't interpret the backslashes. This is VERY handy for
> things like regular expressions!

One thing to be aware of:
Raw strings cannot end in a backslash.
If you need that, you can write a constant expression:
r"c:=netreskit\sc" "\\"

-- 
Christian Tismer             :^)   <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101   :    *Starship* http://starship.python.net
10553 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     we're tired of banana software - shipped green, ripens at home




More information about the Python-list mailing list