用于表情符号的Python unicode字符转换

用于表情符号的Python unicode字符转换,python,string,unicode,formatting,emoji,Python,String,Unicode,Formatting,Emoji,我在将字节顺序标记格式化为unicode时遇到一些问题。我的性格是如何表现出来的,这有点奇怪。基本上,它不是在Python中打印表情符号,而是字符串。这是我的例子 # these codes are coming from a json file; this a representation of one of the codes. e = 'U+1F600' # smile grin emoji # not sure how to clean this, so here's a basic

我在将字节顺序标记格式化为unicode时遇到一些问题。我的性格是如何表现出来的,这有点奇怪。基本上,它不是在Python中打印表情符号,而是字符串。这是我的例子

# these codes are coming from a json file; this a representation of one of the codes.
e = 'U+1F600' # smile grin emoji

# not sure how to clean this, so here's a basic attempt using regex.
b = re.compile(r'U\+', re.DOTALL).sub('\U000', e)

print unicode(b) # output should be '\U0001F600'
不管出于什么原因,这不会打印表情符号字符

但是,如果键入与文本相同的字符串,则使用
u
标记,一切都会按预期工作

print u'\U0001F600'
我做错了什么?我原以为
unicode
函数会将我的字符串转换为等效的工作字符串,但显然不是


我正在使用Python 2.7

我想
解码
就是您想要的

>>b='\U0001F600'
>>>打印b.decode('unicode-escape')

开始工作了!感谢@nu11p01n73R对您的帮助。这种不正常的原因是什么?这会以什么方式改变输出?@lindsay我添加了一个解释。希望如此helps@nu11p01n73R,在命令后显示的表情符号的数据类型是什么,b的数据类型是什么?@AkshayKathpal
b
的类型是
str