I've been trying to output
as '\U0001f604' instead of the smiley but it doesn't seem to work.
i tried using repr() but it gives me this '\xf0\x9f\x98\x84'. Currently it outputs as the smiley which is not what I wanted. encode('unicode_escape') gives me a UnicodeDecodeError.
The smiley was passed as a string to a class method in python. i.e. "I am happy
"
Appreciate if anyone could help.
Sorry for the big smiley. The markdown doesn't seem to work here.
解决方案
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')