Get the App
SLTechnology News&Howtos  ›  Development  › 

How python deals with emoji emoticons

Shulou Source: shulou.com Published: 2022-06-01 12:02:50 10月02日 Update

This article mainly explains "how python handles emoji expressions". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "how python handles emoji expressions" together!

I. Installation of emoji library pip install emoji II. Role of function

The emoji library has two main functions:

emojize(): Generate emoji based on code

demojize(): decode emoji into code

Code vs. emoji: Portal

1、emojize()

In the application, you need to modify the code slightly, add: at both ends of the code, and change the space in the middle to_ , such as the first smiley face:

# -*- coding: UTF-8-*-""@Author: Star in the Distance @Time : 2021/5/14 19:28@CSDN Tencent Cloud : https://cloud.tencent.com/developer/column/91164"""import emojia = emoji.emojize(':grinning_face:', use_aliases=True)print(a)2、demojize()

Understand the previous function, then this function is well understood.

Take this smiley face for example.

# -*- coding: UTF-8-*-""@Author: Star in the Distance @Time : 2021/5/14 19:28@CSDN : Tencent Cloud : https://cloud.tencent.com/developer/column/91164"""import emojia = emoji.demojize('???? ', use_aliases=True)print(a)

Compared with the above, I found that the code is not the same, and then I tried it again. The above is a complete writing, but each expression may correspond to a abbreviation.

3. Display of emoticons in different files

The display may be different, but it's essentially the same

III. emoji expression processing in the article

Code:

# -*- coding: UTF-8-*-""@Author: Star in the Distance @Time : 2021/5/14 19:28@CSDN : Tencent Cloud : https://cloud.tencent.com/developer/column/91164"""import emojiimport redef delete_emoji(file_path): with open(file_path, encoding='UTF-8') as f: data = f.read() response = re.sub('(:.*?:) ', '', emoji.demojize(data)) return responsepath = 'D:/emoji test.txt'print(delete_emoji(path)) Thank you for reading, the above is the content of "how python handles emoji", after learning this article, I believe everyone has a deeper understanding of how python handles emoji. The specific use situation still needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: Facial expressions functions UTF-8 Tencent Learning different content articles smiley faces two both ends Code function Writing substance comparison Table that is ideas situations documents Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple Redmi MariaDB OPPO Reno