Stupid "\" question

Wolfgang Grafen wolfgang.grafen at marconi.com
Fri Nov 17 07:59:03 EST 2000


Gene C 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"
> 

Wonder whether you mean:
>>> "a\b\c"
'a\010\\c'

Assume you mean:
>>> import string
>>> s = r"a\b\c"
>>> t = string.replace(s,"\\","\\\\")
>>> t
'a\\\\b\\\\c'
>>> print t
a\\b\\c

regards

Wolfgang



More information about the Python-list mailing list