Python字符串的encode与decode研究心得——解决乱
2020-06-10 本文已影响0人
吓了一跳哦
把写代码过程比较常用的内容收藏起来,如下代码是关于Python字符串的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')