1
我有一个这样的字符串:将字符串转换为字节对象?
text = 'b\'"Bill of the one\\xe2\\x80\\x99s store wanted to go outside.\''
这显然意味着是字节格式,但是当我看对象的类型,它返回:
type(text)
<class 'str'>
我试图编码的字节然后解码,但这是结果:
text.encode("utf-8").decode("utf-8")
'b\'"Bill of the oneâ\x80\x99s store wanted to go outside.\''
如何才能正确格式化文本?
权,但现在'byte_object == B'B \'“的一个\\ \\ XE2法案'''' – brianpck
好吧,我不清楚看到@brianpck的问题我可以理解你的要求,你可以使用ast来表示这个意思。 –