UTF-8

Laurent Pointal laurent.pointal at wanadoo.fr
Sat Mar 10 09:26:42 EST 2007


Olivier Verdier wrote:
<zip>
> My question is the following: how to set a default encoding in
> python? I read an old thread about that and it didn't seem possible
> by then.

You *can* put a sys.setdefaultencoding("utf-8") in your sitecustomize.py
(see Python libs/site-packages/). Note that this function is no longer
available after Python startup.

But, IMHO, this is a *bad idea*, it may break modules which consider default
encoding to be ascii.
You should prefer to put 
        # -*- coding: utf-8 -*- 
at the begining of your sources files. With that you are ok with all Python
installations, whatever be the defautl encoding.
Hope this will become mandatory in a future Python version.

A+

Laurent.






More information about the Python-list mailing list