测试当前编码环境

610阅读 0评论2020-04-04 wwm
分类:Python/Ruby

#coding:utf-8
import sys
import locale

'''
系统的缺省编码(一般就是ascii):sys.getdefaultencoding()  。用于系统一些函数在处理字符串等数据时候,要先知道编码,然后用该编码处理数据

系统当前的编码:locale.getdefaultlocale()
系统代码中临时被更改的编码(通过locale.setlocale(locale.LC_ALL,“zh_CN.UTF-8″)):locale.getlocale()
文件系统的编码:sys.getfilesystemencoding()
终端的输入编码:sys.stdin.encoding
终端的输出编码:sys.stdout.encoding
代码的缺省编码:文件头上# -*- coding: utf-8 –*-
'''
print sys.getdefaultencoding()
print locale.getdefaultlocale()
print  locale.getlocale()
print sys.getfilesystemencoding()
print  sys.stdin.encoding
print  sys.stdout.encoding

上一篇:Python2字符编码问题汇总
下一篇:爬虫:滑动验证解决方法及python实现