How to overcome automatic cyrillic-to-/hex convert

degoor_python at dir.bg degoor_python at dir.bg
Fri Jun 10 12:53:39 EDT 2005


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



More information about the Python-list mailing list