python - 找出一个字符的unicode脚本

标签 python unicode

给定一个 unicode 字符,返回其 script 的最简单方法是什么? (如“拉丁语”、“韩语”等)? unicodedata似乎没有提供这种功能。

最佳答案

我希望有人以前做过,但显然没有,所以这就是我最终的结果。下面的模块(我称之为 unicodedata2)扩展了 unicodedata 并提供了 script_cat(chr),它返回一个元组(脚本名称,类别) Unicode 字符。示例:

# coding=utf8
import unicodedata2
print unicodedata2.script_cat(u'Ф')  #('Cyrillic', 'L')
print unicodedata2.script_cat(u'の')  #('Hiragana', 'Lo')
print unicodedata2.script_cat(u'★')  #('Common', 'So')

模块:https://gist.github.com/2204527

关于python - 找出一个字符的unicode脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9868792/

相关文章:

python - django 教程第 1 部分(p.choice_set.all() 以相反顺序返回)

c++ - 逐个字符地遍历 Unicode 代码点

mysql - UTF-8字符有问题;我看到的不是我存储的

php - 如何创建一个波斯语 file.txt 然后将其分解?

python - 神经网络的输入大小不匹配

python - 分析视频,寻找彩色像素或 Logo

excel - Excel for Mac 2016 是否可以正确导入 .csv 文件中的 Unicode?

windows - 获取 unicode 符号的别名

python - 在 Python 中解包的多个 for 循环迭代器

python - 如何更改 python Mayavi 的窗口标题?