[Python-ideas] changing sys.stdout encoding
jimjjewett at gmail.com
Mon Jun 11 16:21:29 CEST 2012
On Thu, Jun 7, 2012 at 5:00 PM, Mike Meyer <mwm at mired.org> wrote:
> On Thu, Jun 7, 2012 at 4:48 PM, Rurpy <rurpy at yahoo.com> wrote:
>> I suspect the vast majority of
>> programmers are interested in a language that allows
>> them to *effectively* get done what they need to,
The problem is that your use case gets hit by several special cases at once.
Usually, you don't need to worry about encodings at all; the default
is sufficient. Obviously not the case for you.
Usually, the answer is just to open a file (or stream) the way you
want to. sys.stdout is special because you don't open it.
If you do want to change sys.stdout, usually the answer is to replace
it with a different object. Apparently (though I missed the reason
why) that doesn't work for you, and you need to keep using the same
So at that point, replacing it with a wrapped version of itself
probably *is* the simplest solution.
The remaining problem is how to find the least bad way of doing that.
Your solution does work. Adding it as an example to the docs would
probably be reasonable, but someone seems to have worked pretty hard
at keeping the sys module documentation short. I could personally
support a wrap function on the sys.std* streams that took care of
flushing before wrapping, but ... there is a cost, in that the API
gets longer, and therefore harder to learn.
> or applications
> outside of those built for your system that have a "--encoding" type
There are plenty of applications with an encoding flag; I'm not sure
how often it applies to sys.std*, as opposed to named files.
More information about the Python-ideas