我在格式化字节顺序标记为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
是一个str
类型。 - nu11p01n73R