美文网首页Linux Troubleshooting
Python2.7修改默认编码utf-8

Python2.7修改默认编码utf-8

作者: yangqing | 来源:发表于2019-07-04 15:42 被阅读0次

CentOS系统的python环境修改默认编码为utf-8

vim /usr/lib/python2.7/site-packages/sitecustomize.py

# sitecustomize.py
# this file can be anywhere in your Python path,
# but it usually goes in ${pythondir}/lib/site-packages/
import sys
sys.setdefaultencoding('utf-8')

编写Python脚本声明编码

vim  test.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# name: test.py

print('Hello Python!')

相关文章

网友评论

    本文标题:Python2.7修改默认编码utf-8

    本文链接:https://www.haomeiwen.com/subject/jdrrhctx.html