惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

刘荣星的博客

CentOS7 python2 安装 elasticsearch 模块 在VMWare Workstation虚拟机里使用 yubikey Gentoo Gnome 登陆界面开启触摸板轻击 记录几个内网广播包
python3去除emoji表情符号
JavasBoy · 2021-02-20 · via 刘荣星的博客

最近项目中使用load file导入文件到低版本MySQL中遇到卡住问题,最终问题为文本文件中某些行包含了emoji表情符号。所以使用python去掉这个emoji符号,然后再导出数据库。

需要安装如下模块:

https://pypi.org/project/demoji/

安装完demoji模块后需要手动下载emoji json文件,如果服务器无法上网,可以本地电脑运行,然后提取这个codes.json文件上传到服务器对应的目录。

>>> import demoji
>>> demoji.download_codes()
Downloading emoji data ...
... OK (Got response in 0.14 seconds)
Writing emoji data to /Users/brad/.demoji/codes.json ...
... OK

代码如下:

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import os
import demoji

file_path = "org_loadfile.txt"
final_fine = "loadfile.txt"

# 如果最终文件存在,则删除
if os.path.exists(final_fine):
    os.remove(final_fine)

with open(file_path, 'r') as file:
    for line in file:
        # print(demoji.replace(line, "__"))
        # 替换表情符号为 空
        rap_line = demoji.replace(line, "")
        # 写入文件
        with open(final_fine, 'a') as f:
            f.write(rap_line)