在 win cmd 中 python 产生 "\xb7\xa2\xc9\xfa\xd2\xe2\xcd\xe2\xa1\xa3" 错误输出. 组合 encode, decode, "utf-8", "gb2312" 都没解决.
在 Googlegroups 中找到如下一种转换方法:
#!/usr/bin/env python #coding=utf-8 import sys def conv(i): if len(i) == 2: return chr(int(i, 16)) else: return chr(int(i[0:2], 16))+i[2:] s = sys.argv[1] print ''.join(map(conv, s.split(r'\x')[1:]))
参考: http://python.6.x6.nabble.com/CPyUG-39606-unicode-string-td2749887.html