string.encode on HP-UX

"Martin v. Löwis" martin at v.loewis.de
Sat Jul 24 18:32:37 EDT 2004


Richard Townsend wrote:
> Should I be able to pass the value returned by nl_langinfo() to the
> string.encode call?

I believe all of "yes", "no", and "perhaps not" are valid answers. Yes,
it is intentional that the strings returned by nl_langinfo are
understood as codec names. However, the string is returned from the OS,
and the codec is provided by Python, so it is perhaps not accepted.

But no, you should never ever invoce string.encode with a character
encoding. Instead, you should use string.decode to use encodings in
a meaningful way. It is an unfortunate "feature" that string.encode
is available and does "something".

Regards,
Martin



More information about the Python-list mailing list