On Mon, May 02, 2022 at 07:55:16PM -0000, sam.z.e...@gmail.com wrote:

> 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)
> ```

Thanks for the example, but that doesn't explain the why. Why are we 
redirecting IO to a tty? Assume your audience is not made up of expert 
Linux sys admins who even know what a tty is :-)

(I know what a tty is, kinda, but I still don't know what the above 
does.)



-- 
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/LGZ7J5PLFDTEAHSB3BT6O37MNBH6LSEB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to