如何在Python2.6中打印汉字的unicode字符串?

如何在Python2.6中打印汉字的unicode字符串?,python,unicode,Python,Unicode,这是我要打印的中文字符串統計情報。我想看看python控制台的unicode表示。这个字符串在文件中。 这就是我试过的 import codecs with codecs.open("testutf8.txt", "r", "utf-8") as f: fa=f.read() print fa.encode('utf-8') 这仍然在控制台中打印汉字。 我想在控制台上看到unicode字符串 谢谢unicode转义编码可以显示代码点: >>> s = u'

这是我要打印的中文字符串
統計情報。我想看看python控制台的unicode表示。这个字符串在文件中。
这就是我试过的

import codecs
with codecs.open("testutf8.txt", "r", "utf-8") as f:
     fa=f.read()
     print fa.encode('utf-8')
这仍然在控制台中打印汉字。 我想在控制台上看到unicode字符串


谢谢

unicode转义编码可以显示代码点:

>>> s = u'統計情報'
>>> print(s.encode('unicode-escape'))
\u7d71\u8a08\u60c5\u5831
但是如果您想直接使用这些整数,最好应用
ord

>>> ord(s[0])
32113
>>> 0x7d71
32113
>>> [hex(ord(c)) for c in s]
['0x7d71', '0x8a08', '0x60c5', '0x5831']

我在这里描述的内容在Python2和Python3上都适用。

您想得到Unicode代码点吗,比如:
'\xe7\xb5\xb1\xe8\xa8\x88\xe6\x83\x85\xe5\xa0\xb1'
?可能是
打印repr(fa)
,或者
打印fa.encode(“Unicode转义”)