Unicode & Pythonwin / win32 / console?

Robert kxroberto at googlemail.com
Wed Jan 11 08:49:02 EST 2006


Martin v. Löwis schrieb:
> Robert wrote:
> >>>>win32ui.MessageBox(s)
> >
> > Traceback (most recent call last):
> >   File "<interactive input>", line 1, in ?
> > UnicodeEncodeError: 'ascii' codec can't encode characters in position
> > 12-16: ordinal not in range(128)
>
> Can't comment on that - this is a PythonWin issue.
>
> >>>>print s
> >
> > /devel/test\?????.txt
> >
>
> I see. You need to do "chcp 1251" in your console first, for this
> to print this string correctly (and potentially also set the
> console font to Lucida Console).

is in a PythonWin Interactive session - ok results for cyrillic chars
(tolerant mbcs/utf-8 encoding!).
But if I do this on Win console (as you probably mean), I get also
encoding Errors - no matter if chcp1251, because cyrillic chars raise
the encoding errors also.
I think this is not a good behaviour of python to be so picky. In
1136925967.990106.299760 at g44g2000cwa.googlegroups.com I showed, how I
solved this so far. Any better/portable idea?

> However, if you would do the same on a Russian Windows installation,
> the user will not need to change anything - cyrillic letters come
> out right. Likewise for Umlauts in a German windows installation,
> and Greek letters in a Greek installation.

Yes. But the original problem is, that occasionally unicode strings
(filenames in my case) arise which are not defined on the local
platform, but have to be displayed (in 'replace' - encoding-mode)
without breaking the app flow. Thats the pain of the default behaviour
of current python - and there is no simple switch. Why should "print
xy" not print something _always_ as good and as far as possible?

Robert




More information about the Python-list mailing list