I18n issue with optik

Thorsten Kampe thorsten at thorstenkampe.de
Sun Apr 1 11:47:04 EDT 2007


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. But that's 
nonsense because the Encoding is declared in the Po (localisation) 
file.

How can I set the encoding of sys.stdout to another encoding? Of 
course this would be a terrible hack if the encoding of the 
localisation changes or different translators use different 
encodings...

Thorsten



More information about the Python-list mailing list