Unicode question

"Martin v. Löwis" martin at v.loewis.de
Fri Jul 28 19:09:19 EDT 2006


Ben Edwards (lists) wrote:
> Firstly sys.setdefaultencoding('iso−8859−1') does not work, I have to do
> sys.setdefaultencoding = 'iso−8859−1'

That "works", but has no effect. You bind the variable
sys.setdefaultencoding to some value, but that value is never used for
anything (do sys.getdefaultencoding() to see what I mean). You could
just as well write

sys.standardkodierung = 'iso-8859-1'

> secondly the following does not give a 'UnicodeError: ASCII encoding
> error:', and I would expect ti to.  In fact it prints out the n with ~
> above it fine:
> 
> sys.setdefaultencoding = 'ascii'
> s = u'La Pe\xf1a'
> print s
> 
> Any insight?

The print statement uses sys.stdout.encoding, not the default encoding.

Regards,
Martin



More information about the Python-list mailing list