ron*_*bai 1 python string unicode encoding python-2.7
我有一个字符串s1 = "\xed\xf3\xb4\x90"
.
>>> x = u"\xed\xf3\xb4\x90"
>>> print x
íó´
Run Code Online (Sandbox Code Playgroud)
我怎么s1
用来打印这个?
我试过了:
s1= "\xed\xf3\xb4\x90"
print unicode(s1)
Run Code Online (Sandbox Code Playgroud)
但我无法得到íó´
.我怎么能得到íó´
?
这里使用的正确编解码器是'latin1'
:
>>> s1= "\xed\xf3\xb4\x90"
>>> print s1.decode('latin1') # same as: unicode(s1, 'latin1')
íó´
Run Code Online (Sandbox Code Playgroud)
但是'unicode-escape'
在这里使用也可以'unicode-escape'
假设字节是编码的,'latin1'
并且OP的字符串中没有unicode转义:
>>> s1= "\xed\xf3\xb4\x90"
>>> print s1.decode('unicode-escape') # same as: unicode(s1, 'unicode-escape')
íó´
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4777 次 |
最近记录: |