Stupid "\" question

Greg Landrum glandrum at
Fri Nov 17 15:33:23 CET 2000

In article <4O9R5.709$n9.126221 at>,
  "Gene C" <gchiaramonte at> wrote:
> If I get an input string from a user or file like this:  "a\b\c"
> How do I convert it to this:  "a\\b\\c"
> Desired behavior:
> >>> s = "a\b\c"
> >>> t = doit(s)  # ???
> >>> t
> "a\\b\\c"

I'm not sure that I completely understand the question.
The "double backslash" representation is standard for a string
which contains backslashes.

So, if you enter the string using the r'' notation:
>>> s = r'a\b\c'
you get:
>>> s
which is, I think, what you want.

The same thing happens if you read the string from the user:
>>> s = raw_input()
>>> s

Is this approaching an answer to your question?


Sent via
Before you buy.

More information about the Python-list mailing list