给定一个unicode字符,返回其脚本的最简单方法是什么(如"Latin","Hangul"等)?unicodedata似乎没有提供这种功能.
geo*_*org 19
我希望之前有人做过,但显然不是,所以这就是我最终的结果.下面的模块(我称之为unicodedata2)扩展unicodedata并提供了script_cat(chr)返回一个unicode char的元组(脚本名称,Caterogy).例:
# 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')
Run Code Online (Sandbox Code Playgroud)
模块:https://gist.github.com/2204527
在我看来,Python unicodedata模块包含用于访问Unicode数据库中的主文件的工具,但对于其他文件没有任何内容:"此数据库中的数据基于UnicodeData.txt文件"
脚本信息位于Scripts.txt文件中.它的格式相对简单(在UAX#44中描述)并且不是非常大(131千字节),因此您可以考虑在程序中解析它.请注意,在Unicode分类中,有"Common"脚本,其中包含在不同脚本中使用的字符,如标点符号.
| 归档时间: |
|
| 查看次数: |
1967 次 |
| 最近记录: |