>
> If you move '\\' to the front of your list of replacement characters,
> things will probably work as you expect.
>
> --
> Jerry
I knew it would be something like that! Thanks for your help.
--
http://mail.python.org/mailman/listinfo/python-list
On Dec 4, 2007 11:33 AM, Nick <[EMAIL PROTECTED]> wrote:
> Try "123 *?/ abc d;o /$'" as the argument... and you get -
>
> 123 \*\?\/ abc d\\;o \/\$
That's because of the order you're doing the replacement. Put a print
statement inside your for loop and you'll see something like this:
input start
Thanks guys, you answered that interactive prompt question really
clearly however, whats going on here. This works now -
>>> working_string = '123;abc'
>>> search_string = ';'
>>> print working_string.replace(search_string, '\\' + search_string)
123\;abc
But this doesn't -
---
import sys
import
Nick wrote:
> Is this expected behavior?
>
s = '123;abc'
s.replace(';', '\;')
> '123\\;abc'
>
> I just wanted a single backslash. I can see why this probably happens
> but i wondered if it is definitely intentional.
What you're seeing on the screen is a "literalization" of the string
> 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(';', '\;'
Nick wrote:
> Hi all,
>
> Is this expected behavior?
>
s = '123;abc'
s.replace(';', '\;')
> '123\\;abc'
>
> I just wanted a single backslash. I can see why this probably happens
> but i wondered if it is definitely intentional.
There is only a single backslash. But the interactive pr
Nick a écrit :
> Hi all,
>
> Is this expected behavior?
>
s = '123;abc'
s.replace(';', '\;')
> '123\\;abc'
>>> print s.replace(';', '\;')
123\;abc
> I just wanted a single backslash.
You got it - even if it's not obvious !-)
> I can see why this probably happens
> but i wondered if
On Dec 4, 2007 10:40 AM, Nick <[EMAIL PROTECTED]> wrote:
> Is this expected behavior?
>
> >>> s = '123;abc'
> >>> s.replace(';', '\;')
> '123\\;abc'
>
Everything is Ok. It's still a single backslash. Try:
>>> print s.replace(';', '\;')
Or
>>> x = s.replace(';', '\;')
>>> print x
Best,
Sergio
Hi all,
Is this expected behavior?
>>> s = '123;abc'
>>> s.replace(';', '\;')
'123\\;abc'
I just wanted a single backslash. I can see why this probably happens
but i wondered if it is definitely intentional.
Thanks
Nick
--
http://mail.python.org/mailman/listinfo/python-list