Stupid "\" question
Greg Landrum
glandrum at my-deja.com
Fri Nov 17 09:33:23 EST 2000
In article <4O9R5.709$n9.126221 at newsread2.prod.itd.earthlink.net>,
"Gene C" <gchiaramonte at yahoo.com> 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
'a\\b\\c'
which is, I think, what you want.
The same thing happens if you read the string from the user:
>>> s = raw_input()
a\b\c
>>> s
'a\\b\\c'
Is this approaching an answer to your question?
-greg
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list