* Leo Kislov (1 Apr 2007 14:24:17 -0700)
> On Apr 1, 8:47 am, Thorsten Kampe <[EMAIL PROTECTED]> wrote:
> > I guess the culprit is this snippet from optparse.py:
> >
> > # used by test suite
> > def _get_encoding(self, file):
> >     encoding = getattr(file, "encoding", None)
> >     if not encoding:
> >         encoding = sys.getdefaultencoding()
> >     return encoding
> >
> > def print_help(self, file=None):
> >     """print_help(file : file = stdout)
> >
> >     Print an extended help message, listing all options and any
> >     help text provided with them, to 'file' (default stdout).
> >     """
> >     if file is None:
> >         file = sys.stdout
> >     encoding = self._get_encoding(file)
> >     file.write(self.format_help().encode(encoding, "replace"))
> >
> > So this means: when the encoding of sys.stdout is US-ASCII, Optparse
> > sets the encoding to of the help text to ASCII, too.
> 
> .encode() method doesn't set an encoding. It encodes unicode text into
> bytes according to specified encoding. That means optparse needs ascii
> or unicode (at least) for help text. In other words you'd better use
> unicode throughout your program.
> 
> > But that's
> > nonsense because the Encoding is declared in the Po (localisation)
> > file.
> 
> For backward compatibility gettext is working with bytes by default,
> so the PO file encoding is not even involved. You need to use unicode
> gettext.

You mean

gettext.install('test', unicode = True)
    and
description = _(u'THIS SOFTWARE COMES WITHOUT WARRANTY, LIABILITY OR 
SUPPORT!') ?

If I modify my code like this, I don't get any traceback anymore, but 
the non-ascii umlauts are still displayed as question marks.


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

Reply via email to