> Is this expected behavior?
> 
>>>> s = '123;abc'
>>>> s.replace(';', '\;')
> '123\\;abc'

You're asking the interpreter to print a representation of your 
string, so it does so.  Representations wrap the results in 
quotes and escape characters within that need escaping.

 >>> s.replace(';', '\;')
'123\\;abc'
 >>> print repr(s.replace(';', '\;'))
'123\\;abc'
 >>> print s.replace(';', '\;')
123\;abc

Additionally, it's best-practice to use raw strings or literal 
backslashes, making your replacement either

   r'\;'

or

   '\\;'

because depending on the character following the back-slash, it 
may be translated as a character you don't intend it to be.

-tkc


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to