Reliably getting/setting the (current) encoding name?

Michael Hudson mwh at python.net
Fri Jan 31 10:16:02 EST 2003


"Mike C. Fletcher" <mcfletch at rogers.com> writes:

> The codecs module doesn't appear to have a "get default codec name"
> function.  So I'm asking the question:
> 
>     How does one reliably get the currently-active default codec name
>     (i.e. the one that reflects the currently-set locale) as suitable
>     for use with uncode.encode( ... )?

I don't know the answer to this one, I'm afraid.

> and idealy:
> 
>     How does one set the default encoding to be used by:
>         str( unicode )
>     and
>         "My log message: value = %s"%( unicode )
>     ?
> 
> to avoid ASCII-encoding errors everywhere, without having to add
> conversion code all over the joint?

Here I'd say: don't add conversion code "all over the joint", add it
"at the edges", i.e. where the unicode strings get into your library.

Cheers,
M.

-- 
 All parts should go together without forcing. You must remember that
 the parts you are  reassembling were disassembled by you.  Therefore,
 if you can't get them together again, there must be a reason. By all
 means, do not use a hammer.           -- IBM maintenance manual, 1925




More information about the Python-list mailing list