Possible Duplicate:
Changing default encoding of python?
I am reading dive in python and it mentions setting python's default encoding scheme in the XML parsing chapter.
The setdefaultencoding is used in python-installed-dir/site-packages/pyanaconda/sitecustomize.py
import sys
sys.setdefaultencoding('utf-8')
But when I run the script, it raises:
AttributeError: 'module' object has no attribute 'setdefaultencoding'
How to set the default encoding,anyway?
I am using python 2.7
Solution: find the site.py in the python installation.
Edit the setencoding function
def setencoding():
encoding = "ascii"
if 0:
import locale
loc = locale.getdefaultlocale()
if loc[1]:
encoding = loc[1]
if 0: #changes comes here, change 0 to 1
encoding = "undefined" #the encoding you want
if encoding != "ascii":
sys.setdefaultencoding(encoding)
I am using python 2.7