Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do only some CLDR Short Names work in python?

I want to add reactions on a discord bot, but only some of my Emoji CLDR Short Names work.

For example:

If I use '\N{grinning face}' it works, '\N{thumbs up}' however does not. Instead it shows this message:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-15: unknown Unicode character name

Same with '\N{green heart}' and '\N{red heart}'

I looked the CLDR Short Name up on the unicode.org page; are they just wrong or is it something else?

like image 886
MegaAndi3000 Avatar asked Mar 03 '26 15:03

MegaAndi3000


1 Answers

Escape sequence \N{name} = Character named name in the Unicode database. Use

'\N{thumbs up sign}'
'πŸ‘'

Note that abovementioned link is to the last Unicode version (currently 13.0, I think) while your Python could use another one:

import unicodedata
unicodedata.unidata_version
'12.1.0'

FYI, excerpting from abovementioned UnicodeData.txt using the "\bheart\b" regex gives the following:

Char CodePoint Description
---- --------- -----------
   β˜™ U+2619    Reversed Rotated Floral Heart Bullet
   β™‘ U+2661    White Heart Suit
   β™₯ U+2665    Black Heart Suit
   ❣ U+2763    Heavy Heart Exclamation Mark Ornament
   ❀ U+2764    Heavy Black Heart
   β₯ U+2765    Rotated Heavy Black Heart Bullet
   ❦ U+2766    Floral Heart
   ❧ U+2767    Rotated Floral Heart Bullet
   βΊ– U+2E96    CJK Radical Heart One
   βΊ— U+2E97    CJK Radical Heart Two
   βΌΌ U+2F3C    Kangxi Radical Heart
  πŸŽ” U+1F394   HEART WITH TIP ON THE LEFT
  πŸ’‘ U+1F491   COUPLE WITH HEART
  πŸ’“ U+1F493   BEATING HEART
  πŸ’” U+1F494   BROKEN HEART
  πŸ’– U+1F496   SPARKLING HEART
  πŸ’— U+1F497   GROWING HEART
  πŸ’˜ U+1F498   HEART WITH ARROW
  πŸ’™ U+1F499   BLUE HEART
  πŸ’š U+1F49A   GREEN HEART
  πŸ’› U+1F49B   YELLOW HEART
  πŸ’œ U+1F49C   PURPLE HEART
  πŸ’ U+1F49D   HEART WITH RIBBON
  πŸ’Ÿ U+1F49F   HEART DECORATION
  πŸ–€ U+1F5A4   BLACK HEART
  😍 U+1F60D   SMILING FACE WITH HEART-SHAPED EYES
  😻 U+1F63B   SMILING CAT FACE WITH HEART-SHAPED EYES
  🀍 U+1F90D   WHITE HEART
  🀎 U+1F90E   BROWN HEART
  🧑 U+1F9E1   ORANGE HEART
  πŸ«€ U+1FAC0   ANATOMICAL HEART
like image 188
JosefZ Avatar answered Mar 06 '26 03:03

JosefZ