Python、unicodedata 名称和代码点值,我缺少什么?

标签 python unicode

我正在处理 unicode 数据字符,我想知道为什么有些在 unicodedata 中没有任何名称?这是一个示例代码,您可以在其中检查 < unknown >

我认为 unicode 数据库中的每个字符都被命名了,顺便说一句,所有这些都是相同的类别,即 [Cc] Other, Control .

另一个问题:如何获取unicode代码点值?是ord(unicodechar)就这样了吗?

我也把文件here (因为编码是一件很奇怪的事情),并且因为我认为我用“不可见”字符剪切和粘贴可能有损。

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

#extracted and licensing from here:
"""
:author: Laurent Pointal <laurent.pointal@limsi.fr> <laurent.pointal@laposte.net>
: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    

最佳答案

I thought that every characters inside unicode database were named

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

Another question: how can I get the unicode code point value? Is it ord(unicodechar) that does the trick?

是的!

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

关于Python、unicodedata 名称和代码点值,我缺少什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10348434/

相关文章:

python - 类型错误 : split() takes no keyword arguments in Python 2. x

java - Java 中的自动 Unicode 字符串格式化

unicode - 为什么iconv可以转换 "É"的预组合形式而不是分解形式(从UTF-8到CP1252)

delphi - 使用 Delphi 6 处理 Unicode 字符

pipe.communicate 的 Python 编码

python - 计算温度的偏导数(温度的水平平流)

python - 数据框替换防止在提供 int64 值时替换不正确的 int32 字段

c - 从 C 文件中读取 unicode 字符

python - Pandas 和 Scikit : memory usage when slicing DataFrame

python - 训练模型和负载模型的精度不同