write Unicode to sys.out.write without access to sitecustomize.py

R

Rob Knop

I would like to tell the system that it's OK to write Unicode to sys.out
and sys.err. However, I'm doing this in a CGI script where I don't have
access to the system directories, and as such can't use
sys.setdefaultencoding in sitecustomize.py.

Is there a way to make this happen?
 
E

exarkun

I would like to tell the system that it's OK to write Unicode to
sys.out
and sys.err. However, I'm doing this in a CGI script where I don't
have
access to the system directories, and as such can't use
sys.setdefaultencoding in sitecustomize.py.

Is there a way to make this happen?

Sure, just replace the two files with versions that know how to encode
the unicode using the correct encoding:

import sys, codecs
info = codecs.lookup('utf-8') # for example
sys.stdout = info.streamwriter(sys.stdout)
sys.stderr = info.streamwriter(sys.stderr)

Jean-Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top