python中文处理

来源:互联网 发布:英格兰长弓手—指算法 编辑:程序博客网 时间:2024/04/30 11:53

# -*- coding:utf-8 -*-

制定编码为utf-8



出现  UnicodeDecodeError: 'utf8' codec can't decode byte 0xa1 in position 0: invalid start byte

可以用 

str = unicode(str, errors='replace')

or

str = unicode(str, errors='ignore')
直接将文字替换掉   前提是文字是不需要的


获得系统的默认编码

import sys
print sys.getdefaultencoding()  



0 0
原创粉丝点击