如何通过描述性名称查找Unicode字符?

3

在Python 2.7中,尝试通过(唯一)名称获取Unicode字符。我在文档中找到的方法对我不起作用:

>>> 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'"
1个回答

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

该模块使用与UnicodeData文件格式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数据。 - user395760
适用于Python 3.4.0。 - Wooble
1
unicodedata.unidata_version 可以获取您的 Python 正在使用的 Unicode 版本。它必须 >= 6.0 才能获得 PILE OF POO。 - Joe Hildebrand

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接