all Python 3unicodedatafunction
unicodedata.name()
character names
Returns the official Unicode name of a character, for example 'CYRILLIC SMALL LETTER SHORT I' for 'й'.
Syntax
unicodedata.name(chr, default=None, /)
Control characters ('\n', '\t') have no name, and without the second argument the function raises ValueError, so pass a default when scanning arbitrary text. It takes exactly one character: a string of length 2 raises TypeError, and a 'й' written as two code points is exactly such a string. It is the best way to identify an invisible character hiding in text.
Examples
import unicodedata
print(unicodedata.name('й')) # → CYRILLIC SMALL LETTER SHORT I
print([unicodedata.name(c, '?') for c in 'a\u00a0\n'])
# → ['LATIN SMALL LETTER A', 'NO-BREAK SPACE', '?']
unicodedata.name('\n') # → ValueError: no such name
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy