Python unicodedata.name

There is a built-in method unicodedata.name that sets the Unicode character, returns a human-readable name, for example:

unicodedata.name(chr(0x2704)) == "WHITE SCISSORS"

Is there anything that will provide the opposite? I am looking for something like:

unicodedata.name("WHITE SCISSORS") == chr(0x2704) or 0x2704

I could easily go over all the possible values, create a map, but it looks like it might be ineffective and hoped that something like this already exists. I am using Python 3, so I am open to 3 solutions.

+4
source share
1 answer

You are looking for unicodedata.lookup:

In [5]: unicodedata.lookup("WHITE SCISSORS")
Out[5]: '✄'

This returns a character, use ordto get an integer sequence number:

In [7]: ord(unicodedata.lookup("WHITE SCISSORS"))
Out[7]: 9988 # hex(9988) is 0x2704
+4
source

All Articles