【发布时间】:2017-05-27 01:35:44
【问题描述】:
我在将字节顺序标记格式化为 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
【问题讨论】:
标签: python string unicode formatting emoji