[Tutor] same output on diferent sys.stdout.encodings
klappnase at freenet.de
Thu Feb 8 11:01:27 CET 2007
On Wed, 07 Feb 2007 17:30:26 +0000
Paulino <paulino1 at sapo.pt> wrote:
> Hi everyone!
> I have some strings that include special characters, to be displayed in
> widget labels ( PyQt4 ).
> The output changes in diferent OS's due to diferent sys.stdout encoding
> Not only the labels in the GUI change, but the source file strings are
> altered when I move from win to linux and vice-versa.
> The solution I found for now was to replace the special characters in
> the source file string for their representation:
> I replaced "é" (e acute ) by "\xe9" wich correpsond to chr(233) in the
> cp1252 encoding.
> The character é (e acute) in linux is not recognized in the source file,
> neither in IDLE nor in Kate
> My win sys.stdout.encoding is cp850 and the linux one is utf-8
> Now I have "d\xe9bito" instead of "débito" (debit in portuguese). By
> passing the string through unicode with the convinient encoding, I
> ensure the labels are exibithed the same in every OS but, this way the
> code is not very readable.
> Is there a way of solving this, keeping the more readable?
Have you tried to declare the encoding in use at the top of your Python source file, like:
# -*- coding: iso-8859-1 -*-
If you put this at the first line of your .py files (of course replace iso-8859-1 with whatever
encoding you use) I think this should do the trick.
I hope this helps
More information about the Tutor