Python撤消Unicode [英] Python Undo Unicode

查看:87
本文介绍了Python撤消Unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下两个变量:

Let's say I have the following two variables:

bob1 = u'bob\xf0\xa4\xad\xa2'

bob2 = 'bob\xf0\xa4\xad\xa2'

如何获取bob1的值作为bob2的值?也就是说,如何展开unicode格式,但保留十六进制值?

How can I get the value of bob1 to be the value of bob2? That is, how do I unroll the unicode formatting but keep the escapped hex value?

如果我这样做:

bob1.encode('utf8')
'bob\xc3\xb0\xc2\xa4\xc2\xad\xc2\xa2'

那是不对的...

帮助!

推荐答案

U + 0000和U + 00FF之间的代码点映射到ISO 8859-1或Latin 1编码中的相同字节值.

Code points between U+0000 and U+00FF map to the same byte value in the ISO 8859-1 or Latin 1 encodings.

>>> u'bob\xf0\xa4\xad\xa2'.encode('latin-1')
'bob\xf0\xa4\xad\xa2'

这篇关于Python撤消Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆