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

推荐订阅源

D
Docker
AI
AI
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
Jina AI
Jina AI
大猫的无限游戏
大猫的无限游戏
博客园 - 【当耐特】
V
Visual Studio Blog
博客园 - Franky
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
Intezer
C
Cybersecurity and Infrastructure Security Agency CISA
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
SegmentFault 最新的问题
腾讯CDC
T
Threat Research - Cisco Blogs
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
Webroot Blog
Webroot Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
小众软件
小众软件
C
Cyber Attacks, Cyber Crime and Cyber Security
Hacker News: Ask HN
Hacker News: Ask HN
T
Tor Project blog
WordPress大学
WordPress大学
雷峰网
雷峰网
J
Java Code Geeks
GbyAI
GbyAI
Recorded Future
Recorded Future
F
Full Disclosure
Cisco Talos Blog
Cisco Talos Blog
S
Secure Thoughts
I
InfoQ
量子位
Forbes - Security
Forbes - Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Threatpost
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
Attack and Defense Labs
Attack and Defense Labs
爱范儿
爱范儿
N
News and Events Feed by Topic
V
Vulnerabilities – Threatpost
L
LINUX DO - 最新话题
A
Arctic Wolf
S
Security Affairs

博客园 - 润之

关于 Excel 中导入 JSON 文件 Git Bash 在使用 pacman 安装软件包时的报错问题处理 .NET 操作 RabbitMQ 踩坑记录 Git Bash 中 pacman 安装软件包失败的问题处理 深度操作系统 deepin 20.8 定制的 SSH 安全模块问题 关于在WSL中使用RabbitMQ的问题 PowerShell脚本编写踩坑记 访问局域网资源,出现“指定的网络密码不正确” 微信图片缓存中的 dat 文件处理 关于禅道的白屏问题 使用xrdp远程管理debian的一些记录 安利一个分支版本的Notepad2 匿名类对象的相关测试 关于 Win10 下使用 IETester 的问题 关于 Windows 10 字体安装目录的问题 关于 NPOI 导出的 Excel 出现“部分内容有问题” 的解决方法 解决美图看看不出现在“Open with”的子菜单中的问题 关于BLOB/TEXT字段存储设计及性能的简单研究 Win10 远程服务器版
Python处理编码汉字的一些方法收集
润之 · 2020-10-06 · via 博客园 - 润之

# \x编码转换为汉字
python2:
str1='\xe6\xb6\xa6\xe4\xb9\x8b'
print unicode(str1,'utf-8')

python3:
str2=b'\xe6\xb6\xa6\xe4\xb9\x8b'
print(str2.decode())


# \u编码转换为汉字
python2:
str1='\u6da6\u4e4b'
print str1.decode('unicode_escape')

python3:
str2='\u6da6\u4e4b'
print(str2.encode('utf-8').decode('utf-8')) // .decode('unicode_escape') 这样不对
注:如果只是输出,直接 print(str2) 就能正确输出中文

# 生成编码(python 2/3 通用)

>>> u'润之'.encode('unicode_escape')
b'\\u6da6\\u4e4b'
>>> u'润之'.encode('utf-8')
b'\xe6\xb6\xa6\xe4\xb9\x8b'