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)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay