Setting stdout encoding
Fabio Zadrozny
fabiofz at gmail.com
Sun Sep 9 16:49:14 EDT 2007
Hi,
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:
http://sourceforge.net/tracker/index.php?func=detail&aid=1580766&group_id=85796&atid=577329
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
sys.setdefaultencoding('cp1252')
#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)
....
Thanks,
Fabio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070909/9056dfb1/attachment.html>
More information about the Python-list
mailing list