我在 XML 文件中打开中文字符串时遇到问题。
Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> from io import open
>>> file = open(u'/senti/cet_2.xml', encoding = u'utf-8')
>>> contents = file.read()
>>> contents
u'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<document>\n
<Topic>\u5584\u826f \u4e30\u5bcc \u9ad8\u8d35</Topic>\n <title T="\u5584\u826f\uff0c \u4e30\u5bcc\uff0c\u9ad8\u8d35">\n
但是,我对 Python 3.3 中的相同代码没有任何问题
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
>>> file = open('/Senti/cet_2.xml', encoding = 'utf-8')
>>> contents = file.read()
>>> contents
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<document>\n
<Topic>善良 丰富 高贵</Topic>\n <title T="善良,丰富,高贵">\n
如何在 Python 2.7 中获得正确的字符串?