python的sitecustomize.py妙用

在zope实例所采用的python的路径中,找到site-packages目录,在此目录中建立一个sitecustomize.py文件,设置相应的权限。文件的内容如下:

import sys

sys.setdefaultencoding("utf-8")  

重启zope实例,这样将解决很多unicodedecodeerror错误。

=========================================

#for python2.7 on ubuntu
/etc/python2.7/sitecustomize.py

#for python2.6 on centOS
/usr/local/lib/python2.6/site-packages/sitecustomize.py

=========================================

http://www.grabner-online.de/div_into/html/ch09s04s03.html
# sitecustomize.py                  
# this file can be anywhere in your Python path,
# but it usually goes in ${pythondir}/lib/site-packages/
import sys
sys.setdefaultencoding('iso-8859-1')

 sitecustomize.py is a special script; Python will try to import it on startup, so any code in it will be run automatically. As the comment mentions, it can go anywhere (as long as import can find it), but it usually goes in the site-packages directory within your Python lib directory.
 setdefaultencoding function sets, well, the default encoding. This is the encoding scheme that Python will try to use whenever it needs to auto-coerce a unicode string into a regular string.

posted @   dkcndk  阅读(6107)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示