Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How python deals with emoji emoticons

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report