representing a literal single slash

dsavitsk dsavitsk at e-coli.net
Sat Sep 14 22:35:24 EDT 2002


"dsavitsk" <dsavitsk at e-coli.net> wrote in message
news:ehSg9.8464$yt3.4491656 at newssrv26.news.prodigy.com...
>
> "Jonathan Claggett" <hellen at claggetts.net> wrote in message
> news:dd5454fb.0209141828.1ad24260 at posting.google.com...
> > Here is an easy question (I'm hoping).
> >
> > I'm trying to process a string so that all doubled up backslashes (\\)
> > are replaced with a single backslash (\).
> >
> > The obvious approach doesn't work since a single backslash can't end a
> > string:
> >
> > str = str.replace('\\', '\') # broken
>
> in the above you are replacing a single slash with, well, with nothing.
try
> >>> str = str.replace('\\\\', '\\') # [not] broken
>
> -d

you might also want to rename that variable.  else the str() function will
be a problem.





More information about the Python-list mailing list