【问题标题】:How to replace emoji to word in a text?如何将表情符号替换为文本中的单词?
【发布时间】:2019-08-20 19:22:01
【问题描述】:

想象一下我有这样的文字?

text = "game is on ???? ????"

如何将文本中的表情符号转换为文字?

这是我尝试过的,下面的这段代码将表情符号转换为单词,但我怎样才能将它替换为原始文本中的表情符号。我想不通。

import emot
[emot.emoji(i).get('mean').replace(':','').replace('_',' ').replace('-',' ') for i in text.split()]

预期输出:

game is on fire fire

我遇到过这两个 python 模块 Emoji, Emot 但我不知道如何成功地将表情符号转换为文本并在文本句子中替换它。

谁能帮忙?

【问题讨论】:

    标签: python python-3.x


    【解决方案1】:

    emoji.demojize 采用可选的delimiters=(":", ":") 参数。改成("", "")

    import emoji
    text = "game is on ? ?"
    emoji.demojize(text, delimiters=("", ""))  # 'game is on fire fire'
    

    【讨论】:

    • 谢谢。只是一个外部问题是否也可以将表情符号转换为单词?你知道像 :-) 和表情符号一起微笑等。
    • 似乎没有图书馆可以帮助您。你可以在emoji github 上打开一个问题,或者你可以通过looking at this list of emoticons 自己动手并写一堆text.replace("<3", "heart") 或更有效的东西。
    猜你喜欢
    • 2021-08-07
    • 2019-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 2021-01-13
    • 2016-03-22
    • 1970-01-01
    相关资源
    最近更新 更多