Re: How to overcome automatic cyrillic-to-/hex convert

2005-06-12 Thread Florian Diesch
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 But when I enter some Bulgarian (actually cyrillic) text as a string,
 it
 seems that Python automatically converts it to '\x00..\x00 ' and once
 converted that way I can't get it back into its original look. The only
 way to get it right is using print :

 a = 'ÌÀÌÀ' # 'Mam' in Bulgarian
 print a
 'ÌÀÌÀ'

 but

 a
 '\xcc\xe0\xec\xe0'


Did you try the locale module?


   Florian
-- 
begin  signature_virus
 Hi! I'm a signature virus. Please copy me to your signature to help me spread.
end
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to overcome automatic cyrillic-to-/hex convert

2005-06-11 Thread Terry Reedy

[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 But when I enter some Bulgarian (actually cyrillic) text as a string,
 it
 seems that Python automatically converts it to '\x00..\x00 ' and once
 converted that way I can't get it back into its original look. The only
 way to get it right is using print :

 a = 'ÌÀÌÀ' # 'Mam' in Bulgarian
 print a
 'ÌÀÌÀ'

 but

 a
 '\xcc\xe0\xec\xe0'

There is a difference between internal data and external presentation. 
Print a calls str(a) to get a 'nice' presentation.  Echoing 'a' calls 
repr(a) to get an invertible presentation (eval(repr(somestring)) == 
somestring).  Internally, 'a' is the 4 bytes indicated by the repr 
presentation, not the 16 chars displayed in that presentation.  There is no 
conversion until that presentation.

I cannot comment about wxGrid and how to get it to display the nice version 
you want.

Terry J. Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list

How to overcome automatic cyrillic-to-/hex convert

2005-06-10 Thread degoor_python
Hi friends,

I am really sorry to bother you with such a simple stupid question but
today it's my second day spent in searching manuals, mail-archives
(I downloaded over 100MB from python-list),
etc., and I could not find anything that can solve the matter.

I am from Bulgaria and I use Python (+wxPython+Boa Constructor) as a
front-end to database processing with Firebird. I use Python 2.4.1 over
Windows 98 SE. My keyboard is set as default Bulgarian keyboard (keybg)
so I can write in Bulgarian using win32 application as well in MS DOS
prompt. That should correspond to 'cp1251' (win32) and 'cp855' (DOS
console) encodings.

But when I enter some Bulgarian (actually cyrillic) text as a string,
it
seems that Python automatically converts it to '\x00..\x00 ' and once
converted that way I can't get it back into its original look. The only
way to get it right is using print :

 a = '' # 'Mam' in Bulgarian
 print a
''

but

 a
'\xcc\xe0\xec\xe0'

It is not such a great problem that the string enters or gets out of
the
database in that look as long as the user doesn't see it. But when it
comes to data visualization I can't expect the user to know what
'\xcc\xe0\xec\xe0' mean, neither can I use (at least as much as I know)
'print' for that job. To visualize data in the base I use table views
created with wxGrid. In the grid instead of '' I am getting
'\xcc\xe0\xec\xe0'.

To set the value of a particular cell in the grid I use
wxGrid::SetCellValue :

self.grid1.SetCellValue(row, column, string)

In one of O'Reilly's Python books (Learning Python, chapter 8.3.2)there
is a hint that it is possible to redirect the standard output to a
user-defined object but it is not quite clear how that can be achived
and if that is applicable in my case at all.

Your help is of great need and would be truely appreciated!

Thank you very much!

degoor
-- 
http://mail.python.org/mailman/listinfo/python-list