字符串的encode与decode解决乱码问题

!/usr/bin/env python

coding=utf-8

s="中文"
if isinstance(s, unicode):

s=u"中文"

print s.encode('gb2312')
else:

s="中文"

print s.decode('utf-8').encode('gb2312')

原文地址:https://www.cnblogs.com/chenjingyi/p/5740261.html