码迷,mamicode.com
首页 > 其他好文 > 详细

乱码的解决方法

时间:2019-09-25 12:55:09      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:字符   load   转码   lte   其他   efault   code   解决方法   odi   

一.确定字符串类型

import chardet
str=中文~
print str(chardet.detect(str))

二.根据类型转码

str=str.decode(GB2312).encode(utf-8)
#先将字符串由得到的类型转为undecode,再转为其他字符类型

三.代码前添加

# -*- coding: utf-8 -*-
reload(sys)
sys.setdefaultencoding(utf-8)

 

乱码的解决方法

标签:字符   load   转码   lte   其他   efault   code   解决方法   odi   

原文地址:https://www.cnblogs.com/moshuixiong/p/11583549.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!