sys.setedefaultencoding()

Fredrik Lundh fredrik at pythonware.com
Fri Jul 4 11:23:07 EDT 2003


Facundo Batista:

> Learning (and needing it) Unicode, in Dive Into Python found the
> sys.setedefaultencoding() method. Very nice, but in the documentation of the
> 2.2.1 version, says that this method is new in 2.0 version.
>
> I've got installed Python 2.1.1 and when I do dir(sys), don't get that
> method!! Strange. And ugly, :(

sys.setdefaultencoding() shouldn't be used by application programs;
it was added for test purposes only.

if you really need to change the encoding, tweak site or sitecustomize,
and be aware that 1) python programs you write may not work on other
systems, and 2) extensions may not work properly on your system.

> - Why this happens?

site.py removes the function.

> - How can I, by a different method, set the default encoding?

the default encoding is ASCII, and shouldn't be changed.  good practice
is to decode data on the way in, use Unicode strings on the inside, and
encode data on the way out.

(see the codecs module for information on how to created encoded
streams).

</F>








More information about the Python-list mailing list