sys.setdefaultencoding

R

Robin Becker

Can someone explain the rationale of making the default encoding a sitewide setting?

I could live with the the default being set on a per process basis, but it
baffles me why even that possibility is taken away as site.py removes
sys.setdefaultencoding.

Is there a way to allow the process to specify that unicode-->str should use
'utf8' rather than 'ascii' in all non-specific cases?
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Is there a way to allow the process to specify that unicode-->str should
use 'utf8' rather than 'ascii' in all non-specific cases?

No. Things might break if you change the default encoding to anything
but ASCII, and more so if you do that "at runtime". For example,
dictionaries with Unicode keys may stop working, and the cached
byte-oriented version of a Unicode string may become incorrect.

In general, programs and libraries should not rely on the default
encoding for anything. Instead, they should convert explicitly,
either from an explicitly specified encoding, or one derived from
the context. Experience has shown that this is possible in nearly
every case (and in all cases if an appropriate refactoring is made).

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top