print() and unicode strings (python 3.1)

7stud bbxx789_05ss at
Mon Aug 24 18:54:03 CEST 2009

On Aug 24, 9:56 am, "Martin v. Löwis" <mar... at> wrote:
> > I don't understand why I'm getting an encode error in python 3.1.
> The default encoding is not relevant here at all. Look at
> sys.stdout.encoding.
> Regards,
> Martin


Thanks for the response.  I get US-ASCII for both 2.6 and 3.1:

===python 3.1======
import sys


$ python3.1

I can't figure out a way to programatically set the encoding for
sys.stdout.  So where does that leave me? python 3.1 won't let me
explicitly encode my unicode string, and python 3.1 implicitly does
the encoding with the wrong codec.  And why would any programmer rely
on python 3.1's implicit encoding of unicode strings anyway?
Presumably, different systems will have different encodings for
sys.stdout, some encodings might cause encode errors.

More information about the Python-list mailing list