how to replace double backslash with one backslash in string...

Vincent Texier vit at free.fr
Thu Jul 1 09:03:27 EDT 2004


Thanks for all, it works !

I will test the presence of quotes to be safe...

Thanks again.
Vince.

Eric Brunel wrote:

 > If you're sure you'll never have any quote in the string, you can try to
 > do eval("'%s'" % myStringVar.get())
 >
 > Example:
 >  >>> s = r'\x20\x01\x21'
 >  >>> s
 > '\\x20\\x01\\x21'
 >  >>> eval("'%s'" % s)
 > ' \x01!'
 >
 > Note that this may be dangerous, since the eval will take place in your
 > program, so it can break things if you're not careful. Checking that it
 > does not contain any quotes may be a good start.
 >
 > HTH
tart.
> 
> HTH




More information about the Python-list mailing list