将 Unicode 字符串转换为 Python 中的字符串(包含额外符号) [英] Convert a Unicode string to a string in Python (containing extra symbols)

查看:81
本文介绍了将 Unicode 字符串转换为 Python 中的字符串(包含额外符号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 Unicode 字符串(包含 £ $ 等额外字符)转换为 Python 字符串?

How do you convert a Unicode string (containing extra characters like £ $, etc.) into a Python string?

推荐答案

参见 <代码>unicodedata.normalize

title = u"Klüft skräms inför på fédéral électoral große"
import unicodedata
unicodedata.normalize('NFKD', title).encode('ascii', 'ignore')
'Kluft skrams infor pa federal electoral groe'

这篇关于将 Unicode 字符串转换为 Python 中的字符串(包含额外符号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆