相关疑难解决方法(0)

为什么unicodedata不识别某些字符?

至少在Python 2中,unicodedata.name()不识别某些字符.

ActivePython 2.7.0.2 (ActiveState Software Inc.) based on
Python 2.7 (r27:82500, Aug 23 2010, 17:17:51) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from unicodedata import name
>>> print(u'\n')


>>> name(u'\n')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: no such name
>>> name(u'a')
'LATIN SMALL LETTER A'
>>>
Run Code Online (Sandbox Code Playgroud)

(第一个print是证明Python本身可以识别u'\n'为换行符.)

当然Unicode 包含字符\n,它有一个名称,特别是"LINE FEED".

NB.unicodedata.lookup('LINE FEED') …

python unicode

13
推荐指数
1
解决办法
1340
查看次数

标签 统计

python ×1

unicode ×1