Unicode encoding/decoding

跟風遠走 提交于 2019-12-23 18:10:08

问题


I have a string that looks like this.

st = '/M\xe4rzen'

I would like to covert this to unicode. How can I do this? I've tried:

st.decode('utf-8')
unicode(t, 'utf-8')

The original file is utf-8 encoded, but I can't seem to get the unicode representation of the string.


回答1:


Your data is not UTF8 encoded; more likely it is using the Latin-1 encoding:

>>> print st.decode('latin1')
/Märzen

Calling .decode() is enough, no need to also call unicode().



来源:https://stackoverflow.com/questions/15637419/unicode-encoding-decoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!