Setting stdout encoding

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Sep 10 05:25:50 EDT 2007


En Sun, 09 Sep 2007 17:49:14 -0300, Fabio Zadrozny <fabiofz at gmail.com>
escribi?:

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

The encoding can be set using the C API for file objects - from Python
code, use ctypes:

py> from ctypes import *
py> PyFile_SetEncoding = pythonapi.PyFile_SetEncoding
py> PyFile_SetEncoding.argtypes = (py_object, c_char_p)
py> if not PyFile_SetEncoding(sys.stdout, "hex"):
...     raise ValueError
...
py> print "Hello"
Hello
py> print u"Hello"
48656c6c6f

--
Gabriel Genellina




More information about the Python-list mailing list