On Mon, May 02, 2022 at 05:29:56PM -0000, sam.z.e...@gmail.com wrote:

> > There's already contextlib.redirect_stdout() and
> > contextlib.redirect_stderr(). Adding contextlib.redirect_stdin() would
> > be logical, but I think a more flexible
> > 
> >     contextlib.redirect_stdio(stdin=None, stdout=None, stderr=None)
> >
> > would be better - where None (the default) means "leave this alone".

Seems kinda useful, but I have two concerns.

(1) Perhaps this would be better as a recipe using ExitStack (plus a new 
redirect_stdin)?

https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack


(2) I don't see `redirect_stdio(stout=None ...)` as meaning "leave 
stdout alone". I see it as equivalent to some variation of unsetting 
stdout, say setting it to /dev/null.

I don't know how I would *not* redirect stdout, except to just not 
redirect it.

Overall:

Add redirect_stdin: +1 (regardless of what we do with redirect_stdio)

Add an ExitStack recipe: +1

Add redirect_stdio: -0

Use None to mean "don't change": -1

Use None to mean "redirect to nowhere": +1


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/GNJX2FKDQY2RI2OPG2IQ74QFIYKBQWS2/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to