我写了这段代码:
'\xe4\xf6\xfc'.decode('latin1')
但是我得到了这个:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'
我正在使用python 3.4,并且在Mac上正在使用python。
因为字符串类型不支持.decode()
Python 3中的方法。只需在字符串前面加上b
,即可将其转换为bytes
类型:
>>> b'\xe4\xf6\xfc'.decode('latin1')
'äöü'
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句