我想打印这样编码的字符串:"Cze\u00c5\u009b\u00c4\u0087"
,但我不知道如何打印。示例字符串应打印为:“Cześć”。在
我尝试的是:
str = "Cze\u00c5\u009b\u00c4\u0087"
print(str)
#gives: CzeÅÄ
str_bytes = str.encode("unicode_escape")
print(str_bytes)
#gives: b'Cze\\xc5\\x9b\\xc4\\x87'
str = str_bytes.decode("utf8")
print(str)
#gives: Cze\xc5\x9b\xc4\x87
在哪里
^{pr2}$给出“Cześć”,但我不知道如何将"Cze\xc5\x9b\xc4\x87"
字符串转换为b"Cze\xc5\x9b\xc4\x87"
字节。在
我也知道问题是在用"unicode_escape"
参数编码基本字符串后字节表示中的附加反斜杠,但我不知道如何删除它们-str_bytes.replace(b'\\\\', b'\\')
不起作用。在
使用
raw_unicode_escape
:相关问题 更多 >
编程相关推荐