[Python-ideas] Re: contextlib.redirect_stdio function
sam.z.ezeh@gmail.com wrote: > I've now created a GitHub issue [2] and a draft PR [3] for > contextlib.redirect_stdin. To provide an update, contextlib.redirect_stdin isn't happening [1] [1]: https://github.com/python/cpython/issues/92178#issuecomment-1115486367 ___ 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/6FVN3AURPGZMJ6EBF5D5ZK5HYK6Z3FVE/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: contextlib.redirect_stdio function
> (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. This makes sense, perhaps None could be an alias for a stream created from os.devnull [1]. Then the default arguments for stdin, stdout, stderr would be sys.stdin, sys.stdout and sys.stderr respectively. I've now created a GitHub issue [2] and a draft PR [3] for contextlib.redirect_stdin. [1]: https://docs.python.org/3/library/os.html#os.devnull [2]: https://github.com/python/cpython/issues/92178 [3]: https://github.com/python/cpython/pull/92180 ___ 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/35P76FP2H7Y72Q4BMOG7YRVR53LUQWCY/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: contextlib.redirect_stdio function
On Mon, May 02, 2022 at 05:29:56PM -, 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/