我有一个字符串,其中包含编码字节:
str1 = "b'Output file \xeb\xac\xb8\xed\x95\xad\xeb\xb6\x84\xec\x84\x9d.xlsx Created'"
我想解码它,但我不能,因为它已经变成了一个字符串。所以我想问一下有什么办法可以将其转换为
str2 = b'Output file \xeb\xac\xb8\xed\x95\xad\xeb\xb6\x84\xec\x84\x9d.xlsx Created'
Here str2
is a bytes
我可以使用它轻松解码的对象
str2.decode('utf-8')
得到最终结果:
'Output file 문항분석.xlsx Created'
你可以使用ast.literal_eval https://docs.python.org/3/library/ast.html#ast.literal_eval:
>>> print(str1)
b'Output file \xeb\xac\xb8\xed\x95\xad\xeb\xb6\x84\xec\x84\x9d.xlsx Created'
>>> type(str1)
<class 'str'>
>>> from ast import literal_eval
>>> literal_eval(str1).decode('utf-8')
'Output file 문항분석.xlsx Created'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)