moshuixiong

一.确定字符串类型

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\')

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-08-11
  • 2021-03-30
  • 2021-09-19
  • 2020-11-17
  • 2021-11-16
  • 2021-12-26
猜你喜欢
  • 2021-12-03
  • 2021-08-19
  • 2022-01-12
  • 2021-10-07
  • 2022-12-23
  • 2021-07-20
相关资源
相似解决方案