4

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?

ibexy
  • 609
  • 3
  • 16
  • 34

2 Answers2

1

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.

pigeonburger
  • 715
  • 7
  • 24
  • tried this before and now gain. The literal value: \U0001F600 is displayed in twitter – ibexy Sep 25 '21 at 10:54
  • @ibexy: could be that the data is intrepreted as JSON encoded (no further encoding), at which point you'd need to use the JSON syntax, using UTF-16 surrogate pairs. – Martijn Pieters Jan 01 '23 at 14:48
0

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

user16930239
  • 6,319
  • 2
  • 9
  • 33