DEV Community

Giancarlo Rocha
Giancarlo Rocha

Posted on

Quick Fix For Python UnicodeEncodeError When Trying To Print An Encoded Emoji

If you have encoded emojis in a string, and you can't print them, do this:

>>> data = "Those are emojis -> \ud83d\ude2e\ud83d\ude02\ud83d\ude02"
>>> data.encode('utf-16', 'surrogatepass').decode('utf-16')
'😮😂😂'
Enter fullscreen mode Exit fullscreen mode

This should work with any character encoded as two 16-bit hex value.

Top comments (0)