我正在处理unicode数据字符,不知道为什么有些字符在unicodedata中没有任何名称?这是一个示例代码,您可以在其中检查< unknown >
我以为unicode数据库中的每个字符都被命名了,顺便说一句,所有类别都属于[Cc] Other, Control

另一个问题:如何获取unicode代码点值?这是ord(unicodechar)起作用的吗?

我还放置了文件here(因为编码是一件很奇怪的事情),并且因为我认为带有'invisible'字符的cut n'粘贴可能有损。

#!/bin/env python
# -*- coding: utf-8 -*-

#extracted and licensing from here:
"""
:author: Laurent Pointal <[email protected]> <[email protected]>
:organization: CNRS - LIMSI
:copyright: CNRS - 2004-2009
:license: GNU-GPL Version 3 or greater
:version: $Id$
"""

# Chars alonemarks:
#         !?¿;,*¤@°:%|¦/()[]{}<>«»´`¨&~=#±£¥$©®"
# must have spaces around them to make them tokens.
# Notes: they may be in pchar or fchar too, to identify punctuation after
#        a fchar.
#        \202 is a special ,
#        \226 \227 are special -
alonemarks = u"!?¿;,\202*¤@°:%|¦/()[\]{}<>«»´`¨&~=#±\226"+\
     u"\227£¥$©®\""
import unicodedata
for x in alonemarks:
    unicodename = unicodedata.name(x, '<unknown>')
    print "\t".join(map(unicode, (x, len(x), ord(x), unicodename, unicodedata.category(x))))

    # unichr(int('fd9b', 16)).encode('utf-8')
    # http://stackoverflow.com/questions/867866/convert-unicode-codepoint-to-utf8-hex-in-python

最佳答案


不,控制字符没有名称,请参见UnicodeData文件

是的!

print '%x' % ord(unicodedata.lookup('LATIN LETTER SMALL CAPITAL Z'))
## 1d22

10-06 10:48