上一篇
Python设置默认编码为utf8的方法
- 行业动态
- 2024-06-03
- 7
在Python中,可以通过以下方法设置默认编码为utf8:
1、在文件开头添加以下代码:
*coding: utf8 *
2、使用sys
模块设置默认编码:
import sys reload(sys) sys.setdefaultencoding('utf8')
注意:这种方法在Python 3中已经不适用,因为Python 3默认使用utf8编码,如果你使用的是Python 2,可以尝试这种方法。