将句子中的表情符号转换为单词或文字

时间:2019-05-02 06:34:13

标签: python-3.x emoji

我的句子像:“这个地方真棒\ xF0 \ x9F \ x98 \ x89”。我想用相应的文本替换\ xF0 \ x9F \ x98 \ x89。 因此结果就像“这个地方很棒,眨眨眼的微笑”。 我正在使用python3。我想我可以使用emoji包来进行降级,但这需要使用emoji而不是“ \ xF0 \ x9F \ x98 \ x89”。

mystr = "OMG the place is Awesome !!!!!!!!!!!! \xf0\x9f\x98\x9dl"
mystr = mystr.decode('utf-8')
print(emoji.demojize(mystr))

为此我得到错误: AttributeError:“ str”对象没有属性“ decode”

1 个答案:

答案 0 :(得分:1)

ByteString以b表示法开头。

>>> mystr = "OMG the place is Awesome !!!!!!!!!!!! \xf0\x9f\x98\x9dl"
>>> mystr = mystr.decode('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'
>>> mystr = b"OMG the place is Awesome !!!!!!!!!!!! \xf0\x9f\x98\x9dl"
>>> mystr = mystr.decode('utf-8')
相关问题