getdefaultencoding - how to change this?

Antoine Pitrou solipsis at pitrou.net
Thu Jan 20 14:37:01 EST 2011


On 20 Jan 2011 17:20:14 GMT
Helmut Jarausch <jarausch at skynet.be> wrote:
> Thanks Robert,
> probably I wasn't too clear about my issue.
> I couldn't "print" any non-ascii character to my console although
> my console has an en_US.iso88591 locale.

Well, if you want a correct answer, you should paste actual code as
well as its result on your system, rather than start by asking how to
change getdefaultencoding (which you shouldn't do as explained by
others).

> I didn't modfiy anything in Python's source code.
> I noticed that my root account still had an ASCII locale.
> Now I have changed it such that the root account has the same locale
> as non-root accounts. Recompiling Python under such a root account
> has rectified things.

Recompiling Python doesn't change its behaviour wrt. locales and
encodings. All this is done at runtime.

> Now I can print non-ascii characters if they are
> properly encoded.

You can *always* print characters if they are properly encoded. What
you are asking is for Python to guess and do the encoding by itself,
which is a different matter (and a poorly supported one under 2.x;
Python 3 behaves much better in that regard).

Regards

Antoine.





More information about the Python-list mailing list