print python emoji as unicode string

>>> print u'\U0001f604'.encode('unicode-escape')
\U0001f604

Another solution is to use the name aliases and print them using the string literal \N

print('\N{grinning face with smiling eyes}')

Current list of name aliases can be found at https://www.unicode.org/Public/14.0.0/ucd/NamesList-14.0.0d1.txt


I found the solution to the problem.

I wrote the following code:

#convert to unicode
teststring = unicode(teststring, 'utf-8')

#encode it with string escape
teststring = teststring.encode('unicode_escape')

Just add

# -*- coding: UTF-8 -*-

into your code and you will be able to print Unicode characters