Setting stdout encoding

Fabio Zadrozny fabiofz at
Sun Sep 9 22:49:14 CEST 2007


Does someone know if there's a way to explicitly set the stdout/stderr/stdin
encoding that python should use?

What I'm trying to do is make python recognize that the Eclipse output
accepts a different encoding (such as utf-8, cp1252, etc). More details on
the problem can be found at:

The closest I could get to solving this was running a script that went on
and ran the script that should really be executed through the code below
(which I think is a lousy solution, but the only one I could see so far --
and I also have to keep different versions of that for jython, as in jython
that works without any workaround):

---------------------- script giving error ----------------------
print u"unicode char: >>\xF6<<"

---------------------- script I have to run to make it work
if __name__ == '__main__':
    import sys
    reload(sys) #without the reload setdefaultencoding is not accessible

    #go on and make an execfile on the module we actually want to run (we
have to be careful not to mess up that namespace)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list