representing a literal single slash
dsavitsk
dsavitsk at e-coli.net
Sat Sep 14 22:30:34 EDT 2002
"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('\\\\', '\\') # broken
-d
More information about the Python-list
mailing list