python的sitecustomize.py妙用

來源:互聯網
上載者:User

在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.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.