[RELEASED] Python 3.1 final

Hallvard B Furuseth h.b.furuseth at usit.uio.no
Sun Jun 28 23:34:10 CEST 2009

Benjamin Peterson writes:
>Nobody <nobody <at> nowhere.com> writes:
>> On Sun, 28 Jun 2009 19:21:49 +0000, Benjamin Peterson wrote:
>> 1. Does Python offer any assistance in doing so, or do you have to
>> manually convert the surrogates which are generated for unrecognised bytes?
> fs_encoding = sys.getfilesystemencoding()
> bytes_argv = [arg.encode(fs_encoding, "surrogateescape") for arg in sys.argv]
>> 2. How do you do this for non-invertible encodings (e.g. ISO-2022)?
> What's a non-invertible encoding? I can't find a reference to the term.

Different ISO-2022 strings can map to the same Unicode string.
Thus you can convert back to _some_ ISO-2022 string, but it won't
necessarily match the original.


More information about the Python-list mailing list