Get alternative char name with unicodedata.name() if no formal onedefined

D

Dirk Wallenstein

Hi,
I'd like to get control char names for the first 32 codepoints, but they
apparently only have an alias and no official name. Is there a way to
get the alternative character name (alias) in Python?
 
J

John Machin

Hi,
I'd like to get control char names for the first 32 codepoints, but they
apparently only have an alias and no official name. Is there a way to
get the alternative character name (alias) in Python?

AFAIK there is no programatically-available list of those names. Try
something like:

name = unicodedata.name(x, some_default) if x > u"\x1f" else ("NULL",
etc etc, "UNIT SEPARATOR")[ord(x)]

or similarly with a prepared dict:

C0_CONTROL_NAMES = {
u"\x00": "NULL",
# etc
u"\x1f": "UNIT SEPARATOR",
}

name = unicodedata.name(x, some_default) if x > u"\x1f" else
C0_CONTROL_NAMES[x]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top