> (Plus not-yet-existing, but hopefully soon, redirect_stdin.)
Mentioned on the redirect_stdio thread, I've now created a GitHub issue and PR 
for contextlib.redirect_stdin.
> I think I want to see some examples of how and why you would use it, and 
> why one couldn't just use the redirect_stdout context manager.
One aspect that was mentioned in the original thread was the use of readline 
support alongside and arrow-key functionality, I can look into what that means 
in practice. The original post contained the example of switching between 
different terminals.

Using the prospective redirect_stdin context manager, the following code

```
with open("/dev/tty", 'r+') as file:
    with contextlib.redirect_stdin(file), contextlib.redirect_stdout(file):
        name = input('Name: ')

print(name)
```

Could be rewritten like this

```
with open('/dev/tty', 'r+') as file:
    name = input('Name: ', infile=file, outfile=file)

print(name)
```
_______________________________________________
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/K5F5NEKNLXQ5VZXVSLQ5J6HD7YFIXOBJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to