List Info

Thread: same output on diferent sys.stdout.encodings




same output on diferent sys.stdout.encodings
country flaguser name
Portugal
2007-02-07 11:30:26
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 "dxe9bito" 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?
_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

Re: same output on diferent sys.stdout.encodings
country flaguser name
Germany
2007-02-08 04:01:27
On Wed, 07 Feb 2007 17:30:26 +0000
Paulino <paulino1sapo.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 "dxe9bito" 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

Michael
_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

Re: same output on diferent sys.stdout.encodings
user name
2007-02-08 08:38:46
Paulino 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 "dxe9bito" 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.

Kent

_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

Re: same output on diferent sys.stdout.encodings
country flaguser name
Germany
2007-02-08 09:48:16
The Kate editor has also modelines, similar to the python
interpreter:
htt
p://kate-editor.org/article/katepart_modelines

HTH,
Eike.

_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )