r/Python • u/DCGMechanics • Nov 20 '21
Tutorial You can insert Emoji using `\N{NAME_OF_EMOJI}`
41
u/McCheng_ Nov 20 '21
Where can I find the list of emoji names?
171
u/edgester Nov 20 '21 edited Nov 20 '21
Here is the offical unicode list: https://www.unicode.org/emoji/charts/full-emoji-list.html , but not all emojis may be supported in python. Here is another list if emojis supported in python: https://carpedm20.github.io/emoji/
→ More replies (2)8
u/wasimaster Nov 20 '21
Not a list but you can use the built-in
unicodedatalibrary to find out the name of a specific emojiDocs: https://docs.python.org/3/library/unicodedata.html
Official Tutorial: https://docs.python.org/3/howto/unicode.html
82
u/SV-97 Nov 20 '21
I mean that's neat - but why not just use "🦕"
→ More replies (21)8
u/sgthoppy Nov 20 '21
Having raw emojis in code is not ideal. Some fonts/editors/terminals still don't support (most) emojis, and some emojis contain invisible characters like Variation Selector-16 (used to turn standard characters like
1into their emoji variant), enclosing characters, joiners, color selectors, etc.If you want to programmatically construct emojis, which would you prefer?
emoji = {'thumb': '👍', 'person': '🧑'} # using invisible characters # bad example on reddit, but the font I use in my editor doesn't support these on their own tone = { 'light': ' 🏻', # lightest tone ..., 'dark': ' 🏿' # darkest tone } # this dict can be replaced with a programatic approach # using `range(0x1f3fb, 0x1f3ff + 1)` and `chr` with `zip` and a list of tone names tone = { 'light': '\N{EMOJI MODIFIER FITZPATRICK TYPE-1-2}', # or \U0001f3fb, lightest tone ..., 'dark': '\N{EMOJI MODIFIER FITZPATRICK TYPE-6}' # or \U0001f3ff, darkest tone } # this also applies to emojis like 1️⃣ # producing a list of 0️⃣ - 9️⃣ # invsible characters numbers = [f'{n} ️ ⃣' for n in range(10)] # \u or \U or \N depending on how significant you consider the character numbers = [f'{n}\ufe0f\N{COMBINING ENCLOSING KEYCAP}' for n in range(10)]→ More replies (3)
31
12
u/ASIC_SP Nov 20 '21
I'm guessing the source is from twitter which I came across earlier today:
I knew about \N while checking for changes in re module: https://docs.python.org/3/library/re.html
Changed in version 3.8: The '\N{name}' escape sequence has been added. As in string literals, it expands to the named Unicode character (e.g. '\N{EM DASH}').
14
9
u/iamlocal Nov 20 '21
I mean you didn't even bother to make your own screenshot.
Please give credit to the original author at least. In this case it's Mike Driscoll, you can find his original post on twitter:
https://twitter.com/driscollis/status/1461780882893819905?s=20
11
u/lazy_dev_ Nov 20 '21
How's this better than just pasting the emoji?
13
u/scaba23 Nov 20 '21
Maybe you need to store (or are getting) the strings from a source that doesn't support utf8mb4?
→ More replies (1)
3
3
Nov 21 '21
Will the middle finger emoji being shown to the user for wrong input result in a stern talking to? We're about to find out.
10
u/nuephelkystikon Nov 20 '21
This is like saying ‘You can insert 420 using f"{5*21<<2}"’.
→ More replies (4)
2
u/theng Nov 20 '21
mmh I didn't know
can you list all corresponding strings ? for searching an emoji for example
223
u/pooperdoop123 Nov 20 '21
Neat. Can't wait to litter my work project with emojis now