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

Vincent Texier vit at
Thu Jul 1 12:27:20 CEST 2004


I want to send 3 chars in hexa code to the serial port.

So I type in a tkinter entry : "\x20\x01\x21"

The string is set in a StringVar().

When I read the stringVar, I get : "\\x20\\x01\\x21"

The length is 12 and not 3 anymore.

How can I replace the escape character from the string with the 
corresponding char, and get my 3 char string back ?

I've tried a re.sub(r'\\', chr(92)) but chr(92) is a double backslash again.

Thanks for any help.

More information about the Python-list mailing list