[Tutor] same output on diferent sys.stdout.encodings
kent37 at tds.net
Thu Feb 8 15:38:46 CET 2007
> 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?
I think the problem you are having is with the source code encoding, not
sys.stdout.encoding. Probably your editor on linux expects a different
file encoding than what you are using in Windows. Your windows editor is
probably using cp1252; perhaps the linux editor expects utf-8.
You need to get the editors to agree on the source code encoding. Then
put the coding declaration at the top of the file as Michael suggested.
More information about the Tutor