【问题标题】:How to find unicode characters by their descriptive names?如何通过描述性名称查找 unicode 字符?
【发布时间】:2014-07-31 12:12:19
【问题描述】:

尝试通过 python 2.7 中的(唯一)名称获取 unicode 字符。我在docs 中找到的方法对我不起作用:

>>> import unicodedata
>>> print unicodedata.lookup('PILE OF POO')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: "undefined character name 'PILE OF POO'"

【问题讨论】:

    标签: python python-2.7 unicode python-2.x


    【解决方案1】:

    问题是,PILE OF POO 是在 Unicode 6 中引入的。但是,unicodedata 的数据大多是旧的,5.X 版本左右。文档说:

    该模块使用 UnicodeData File Format 5.2.0 定义的相同名称和符号(请参阅http://www.unicode.org/reports/tr44/tr44-4.html)。

    不幸的是,这意味着您对几乎所有Emoji and hieroglyphs 都不走运(如果您对埃及学感兴趣)。

    【讨论】:

    • Python 2.7 使用 Unicode 5.2,Python 3.4 根据文档使用 6.3。其他 3.x 版本可能使用相应较旧的 Unicode 数据。
    • 在 Python 3.4.0 中工作。
    • unicodedata.unidata_version 给出了 Python 使用的 Unicode 版本。必须 >= 6.0 才能获得 PILE OF POO。
    猜你喜欢
    • 2017-12-12
    • 2021-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多