This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author barry
Recipients Marc.Abramowitz, alex, barry, belopolsky, brett.cannon, ezio.melotti, ncoghlan, nikratio, pitrou, rhettinger, vstinner
Date 2013-07-22.14:14:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <20130722101421.7fb0e717@limelight.wooz.org>
In-reply-to <1374461039.42.0.00185582669228.issue15805@psf.upfronthosting.co.za>
Content
In general, I like where this is going.  I agree that a stdout redirector is
probably the most common case, and for that, it almost always (for me)
redirects to an open file.  The use case for stderr redirection is usually,
but not always, to redirect stderr to stdout, but I agree that that is much
more limited.  stdin redirection is much more rare, mostly a testing device,
and better done with mocking.

A suggestion about the name.  Thinking about how it will read in a
with-statement:

    with stdout_to(some_file):
        print('hello')

Since this is all about convenience, I'd mildly suggest an API similar to
built-in open().  I'd rather write this:

    with stdout_to('/tmp/debug.log', 'w', encoding='utf-8'):
        print('hello')

than this:

    with open('/tmp/debug.log', 'w', encoding='utf-8') as tmp_stdout:
        with stdout_to(tmp_stdout):
            print('hello')

stdout_to() could optionally take a single which would be an already open file
object.

Anyway, no doubt you'll paint this bikeshed your own particular color.  Mine
only cost $0.02.
History
Date User Action Args
2013-07-22 14:14:23barrysetrecipients: + barry, brett.cannon, rhettinger, ncoghlan, belopolsky, pitrou, vstinner, ezio.melotti, alex, nikratio, Marc.Abramowitz
2013-07-22 14:14:23barrylinkissue15805 messages
2013-07-22 14:14:23barrycreate