How do I embed emoji into Tweepy status text?

Viewed 363

I have the following code that allows me type a text on the console that then is sent as a comment to tweets.

How can I embed emojis into this?

For example the emoji code for a smile is "U+1F600". When I add this as an entry as follows on the console:

"This is a smile U+1F600", the literal code is appearing on the tweet on the browser instead of the emoji image.

comment = input("[Reply with Comment to tweet:] ")                    
comment_formated="@{0} {1}".format(screen_name,comment)
api.update_status(status = comment_formated, in_reply_to_status_id = id_str)

Please how can I change this so that the picture emojis appear on the browser?

2 Answers

You should copy the emoji from other source like emojipedia and paste it in console when you want it. it will not appear as an emoji in the console, but it will appear correctly on twitter.

console image

"This is a smile "

Alternatively you can use Bytes directly, for example typing \xF0\x9F\x98\x81

you can find all bytes data (UTF-8) for emojis here

Python doesn't accept emojis in the format U+1F600, what you need to do is replace the + with three zeroes 000 and place a backslash \ before the U. Then Python will correctly interpret it as an emoji.

It should now look like \U0001F600. Typing this into your console's window will yield an emoji displaying on Twitter.


Emoji can in some cases also be pasted directly into the console as well, but be aware that not all consoles necessarily support doing this.

Like another answer also describes, you can also directly include the bytes of the emoji, but it's unlikely you'll have those on hand or memorize them.

Related