Re: Escaping the semicolon?

2007-12-04 Thread Nick
> > 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

Re: Escaping the semicolon?

2007-12-04 Thread Jerry Hill
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

Re: Escaping the semicolon?

2007-12-04 Thread Nick
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

Re: Escaping the semicolon?

2007-12-04 Thread Mel
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

Re: Escaping the semicolon?

2007-12-04 Thread Tim Chase
> 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(';', '\;'

Re: Escaping the semicolon?

2007-12-04 Thread Diez B. Roggisch
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

Re: Escaping the semicolon?

2007-12-04 Thread Bruno Desthuilliers
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

Re: Escaping the semicolon?

2007-12-04 Thread Sergio Correia
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

Escaping the semicolon?

2007-12-04 Thread Nick
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