python表情符号编码_在Python中将unicode表情符号转换为ASCII表情符号

Is there a way to translate unicode emojis to an appropriate ascii emoticon in Python? I know the emoji library which can be used to convert unicode emojis to something like :crying_face:. But what I would need is to convert it to :'(

Is there an elegant way to do this without having to translate every possible emoji manually? Another option would be to convert the ascii emojis also to their textual representation, i.e. :'( should become :crying_face:.

My intermediate goal is to find a way to transform ascii and unicode emojis to a common representation. My final goal would be to replace emoticons (no matter if unicode or ascii) by the emotion they represent (if they do not represent an emotion, remove them)

解决方案

I found these repos that have a huge database of emoji's along with a text attribute(what you need):

https://github.com/iamcal/emoji-data (This is the original. The python one seems to be a wrapper on this)

You can find out more by exploring the examples in the repos. From the

For the python version you can use the official unicode name/hex code to get the EmojiChar object:

In [31]: grin = emoji_data_python.find_by_name("GRINNING FACE")

In [32]: grin

Out[32]:

[EmojiChar("GRINNING FACE"),

EmojiChar("GRINNING FACE WITH SMILING EYES"),

EmojiChar("GRINNING FACE WITH STAR EYES"),

EmojiChar("GRINNING FACE WITH ONE LARGE AND ONE SMALL EYE")]

In [33]: grin[0].text

Out[33]: ':D'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值