print() and unicode strings (python 3.1)

7stud bbxx789_05ss at yahoo.com
Mon Aug 24 12:54:03 EDT 2009


On Aug 24, 9:56 am, "Martin v. Löwis" <mar... at v.loewis.de> 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

Hi,

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

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

print(sys.stdout.encoding)


$ python3.1 1test.py
US-ASCII

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