You*_*Tan 17 unicode python-2.7 emoji
我一直在努力输出
作为'\ U0001f604'而不是笑脸,但它似乎不起作用.
我尝试使用repr(),但它给了我'\ xf0\x9f\x98\x84'.目前它输出的笑脸不是我想要的.encode('unicode_escape')给我一个UnicodeDecodeError.
笑脸作为字符串传递给python中的类方法.即"我很高兴
"
感谢是否有人可以提供帮助.
对不起大笑脸.降价似乎在这里不起作用.
Ign*_*ams 19
>>> print u'\U0001f604'.encode('unicode-escape')
\U0001f604
Run Code Online (Sandbox Code Playgroud)
You*_*Tan 12
我找到了问题的解决方案.
我写了以下代码:
#convert to unicode
teststring = unicode(teststring, 'utf-8')
#encode it with string escape
teststring = teststring.encode('unicode_escape')
Run Code Online (Sandbox Code Playgroud)
另一个解决方案是在此处使用简称,并使用字符串文字打印它们\N
print('\N{grinning face with smiling eyes}')
Run Code Online (Sandbox Code Playgroud)
此代码可能会帮助您了解如何简单地打印表情符号:
# -*- coding: UTF-8 -*-
import re
# string = 'Anything else that you wish to match, except URLs http://url.org'
string = 'Anything else that you wish to match'
matches = re.search(r'^(((?!http|https).)+)$', string)
if matches:
print(matches.group(1)+ " is a match ")
else:
print(' Sorry! No matches! Something is not right!')
Run Code Online (Sandbox Code Playgroud)
Sorry! No matches! Something is not right!
Run Code Online (Sandbox Code Playgroud)
Anything else that you wish to match is a match
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
49026 次 |
| 最近记录: |