print python emoji as unicode string

前端 未结 6 1925
谎友^
谎友^ 2020-12-03 13:48

I\'ve been trying to output \"\" as \'\\U0001f604\' instead of the smiley but it doesn\'t seem to work.

i tried

6条回答
  •  情歌与酒
    2020-12-03 14:51

    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')
    

提交回复
热议问题