codecs latin1 unicode standard output file

Martin v. Löwis martin at v.loewis.de
Mon Dec 15 09:48:04 EST 2003


"Marko Faldix" <marko.faldix.tudisweck at mplusr.de> writes:

> print "My umlauts are ä, ö, ü"
> 
> without any encoding-assignment to use for standard output on console AND
> redirecting to file. In latter case, it looks nice with e.g. notepad, just
> strange on console, so settings for console are to adjust and not python
> code. Right?

Wrong. On your operating system, notepad.exe and the console use
*different* encodings. If you think this is stupid, please complain to
Microsoft. If you print byte strings, it will come out wrong either in
the terminal, or in notepad - there is *no way* to have the same byte
string show correctly in both encodings.

If you want to output to a file, you should open the file in
locale.getpreferredencoding(). If you want to output to a terminal,
Python should automatically find out what the terminal's encoding is
(to make things worse, the user can override the terminal encoding
on Windows, on a per-terminal basis, using chcp.exe).

Regards,
Martin





More information about the Python-list mailing list