Unicode to default encoding...

Martin v. Löwis loewis at informatik.hu-berlin.de
Tue Jun 18 07:54:17 EDT 2002


"Gillou" <nospam at bigfoot.com> writes:

> I'm looking for a way to encode an Unicode string to the default encoding
> for the output (console, file...).
> 
> someunicodestring.encode('iso8859-1')
> 
> works for a file (windows & unix) but gives ugly characters on a windows
> console.

This is difficult to do, since you need to find out the "OEM
codepage". On Western European and Northern American Windows
installations, this is either 437 or 850, so "cp437" or "cp850" may
produce proper results.

Notice that the user can change the codepage away from the default.

I believe there is currently no API to find out what code page is used
in a certain console window. You can try parsing the output of chcp.exe.

Regards,
Martin




More information about the Python-list mailing list