[issue5170] logging to file + encoding

Vinay Sajip report at bugs.python.org
Wed Apr 22 13:35:18 CEST 2009


Vinay Sajip <vinay_sajip at yahoo.co.uk> added the comment:

> i think it's all about the difference betwin print(msg) and
> sys.stdout.write('%s\n' % msg)

Yes. Actually, it's about what streams will accept. For example, a
stream opened with codecs.open(encoding='cp1251') will accept a Unicode
string and encode it before output. Likewise, a StringIO wrapped inside
a writer obtained from the codecs module.

However, stdout and stderr are of type file and seem to behave
differently - they behave as expected if I encode the value written to
them, but fail if I write a Unicode string to them.

I don't think special-casing for sys.stdout and sys.stderr in the
logging code is the correct approach. Better to put a conditional
encoding step when it's needed - now I just need to figure out all the
cases when it's needed ;-)

----------
resolution: fixed -> accepted

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5170>
_______________________________________


More information about the Python-bugs-list mailing list