python 编码问题(二)
>>> a = '中文' >>> chardet.detect(a) {'confidence': 0.7525, 'encoding': 'utf-8'} >>> b = a.decode('utf-8') >>> b u'\u4e2d\u6587' >>> c = b.encode('gb2312') >>> c '\xd6\xd0\xce\xc4' >>> d = b.encode('utf-8') >>> d '\xe4\xb8\xad\xe6\x96\x87' >>> e = str(a) >>> chardet.detect(e) {'confidence': 0.7525, 'encoding': 'utf-8'} >>> print a 中文 >>> b u'\u4e2d\u6587' >>> print b 中文 >>> print c ���� >>> print d 中文 >>> print e 中文 >>> a == b False >>> a == c False >>> a == d True >>> a == e True