Q:

How to correct one unicode string like "\u8bf8\u845b\u4eae" in python?

I don't know how they printed strings like "\u8bf8\u845b\u4eae" to  the log files. But now i need to get the correct string from it, it is "诸葛亮" in chinese. I have tried many ways, but failed.
In [56]: print u"\u8bf8\u845b\u4eae"
诸葛亮

In [57]: print "\u8bf8\u845b\u4eae"
\u8bf8\u845b\u4eae

In [58]: "\u8bf8\u845b\u4eae".decode('utf-8')
Out[58]: u'\\u8bf8\\u845b\\u4eae'
In [64]: eval("\u8bf8\u845b\u4eae")
  File "<string>", line 1
    \u8bf8\u845b\u4eae
                 ^
SyntaxError: unexpected character after line continuation character

A:

You have to use: unicode-escape
print '\\u8bf8\\u845b\\u4eae'.encode('ascii').decode('unicode-escape')

also see: Converting Unicode string to Chinese characters

