美文网首页
Python字符串的encode与decode研究心得——解决乱

Python字符串的encode与decode研究心得——解决乱

作者: 吓了一跳哦 | 来源:发表于2020-06-10 14:48 被阅读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') 

相关文章

网友评论

      本文标题:Python字符串的encode与decode研究心得——解决乱

      本文链接:https://www.haomeiwen.com/subject/gqcptktx.html