Home  >  Article  >  Backend Development  >  Python获取系统默认字符编码的方法

Python获取系统默认字符编码的方法

WBOY
WBOYOriginal
2016-06-10 15:10:511195browse

本文实例讲述了Python获取系统默认字符编码的方法。分享给大家供大家参考。具体分析如下:

在Python代码中,普通字符串的编码方式与程序源文件编码方式一致的,而很多IDE在默认情况下,将程序源文件按照系统默认字符编码来保存的。

下面给出用Python获取系统默认编码的例子:

#!/usr/bin/env python
#coding=utf-8
"""
  获取系统默认编码
"""
import sys
print sys.getdefaultencoding()

该段程序在英文WindowsXP上输出为:

ascii

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn