Reliably getting/setting the (current) encoding name?

Mike C. Fletcher mcfletch at
Fri Jan 31 18:26:06 CET 2003

Alex Martelli wrote:

>>    How does one set the default encoding to be used by:
>>        str( unicode )
>with sys.setdefaultencoding -- but UNBINDS that name
>right after trying to import sitecustomize -- the idea being
>that setting the default encoding is a task for the site, NOT
>for authors of libraries etc.
>If you disagree, "reload(sys)" will let you get at
>sys.setdefaultencoding at any time -- use at your own risk.

I don't know whether I disagree per se, but I do find it less than 
convenient :o/.  I suppose for now I will simply require all 
applications using the library to do the reload of sys and set of the 
default encoding to the default encoding for the system.

Asking users to modify doesn't sound appropriate for stand-alone 
GUI applications. locale.getdefaultlocale() should be giving you the 
user's system-set default locale if I'm not mistaken.  In other words, I 
suppose I do disagree :) . It really sounds like something that should 
be set at the operating-system level and accessed automatically by 
Python, with the optional ability to override for particular tasks, 
rather than something for which Python should be creating its own 
setting.  There are probably some valid and important cross-platform 
issues which make that undesirable, of course :) .

Thanks for the explanation,

  Mike C. Fletcher
  Designer, VR Plumber, Coder

More information about the Python-list mailing list