我想要一个反斜杠 - 而不是两个

Car*_*sPl 1 python string backslash

我有一个打印后的字符串是这样的: \x4d\xff\xfd\x00\x02\x8f\x0e\x80\x66\x48\x71

但我想将此字符串更改"\x4d\xff\xfd\x00\x02\x8f\x0e\x80\x66\x48\x71"为不可打印(需要写入串口).我知道这是' \'的问题.如何将此可打印反斜杠替换为不可打印?

Abe*_*bel 5

如果要解码字符串,请使用decode()with 'string_escape'参数,它将变量中的文字解释为python文字字符串(就好像它在代码中键入为常量字符串一样).

mystr.decode('string_escape')
Run Code Online (Sandbox Code Playgroud)