Differences between \N escapes and unicodedata

Chris Angelico rosuav at gmail.com
Fri Aug 5 23:13:28 EDT 2016


Not all Unicode codepoints are supported by unicodedata.name(), but
they are supported in \N escapes and unicodedata.lookup. Is there a
reason for this?

Normally, you can do this:

>>> "\N{GREEK SMALL LETTER OMEGA}"
'ω'
>>> unicodedata.name(_)
'GREEK SMALL LETTER OMEGA'

But check this out:

>>> unicodedata.lookup("CHARACTER TABULATION")
'\t'
>>> "\N{CHARACTER TABULATION}"
'\t'
>>> unicodedata.name(_)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: no such name
>>> unicodedata.lookup("NULL")
'\x00'
>>> "\N{NULL}"
'\x00'
>>> unicodedata.name(_)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: no such name

Tested on 3.4, 3.5, and 3.6. Extremely odd.

ChrisA



More information about the Python-list mailing list