0

I've looked through several questions and I can't seem to find the exact answer to what I need.

I am trying to figure out how to take an emoji and use unicodedata.name() to return it's name.

So for example, I have this emoji: 💩. I want to be able to get it's identifier and get the value of it's name (PILE OF POO). I want to know how to construct the string to pass in to the name function:

unicodedata.name(u'\U0001f4a9')

The above code works. However passing as such:

unicodedata.name(💩)

returns the following:

mojidict['hi'] = unicodedata.name(\U0001f4a9)                                     ^                                 ^
SyntaxError: invalid character in identifier
2
  • 2
    You need to quote the pile of poo. Otherwise you are trying to use it as an identifier instead of a string or character value. Commented Aug 3, 2016 at 2:28
  • Right. I just discovered that. Thanks everyone! Commented Aug 3, 2016 at 2:29

1 Answer 1

2

The solution is very simple:

import unicodedata

unicodedata.name('💩')

which returns:

'PILE OF POO'
Sign up to request clarification or add additional context in comments.

2 Comments

Yup. I just discovered this dumb mistake. Thank you!
You may also need to declare the encoding of the source file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.