[Python-ideas] allow overriding files used for the input builtin

Adam Bartoš drekin at gmail.com
Fri Sep 29 06:56:04 EDT 2017


Hello,

it seems that there are two independent issues – a way to temporarily
replace all sys.std* streams, and a way to use the special interactive
readline logic for arbitrary terminal-like file. I thought that OP's
concern was the latter. In that case shouldn't there just be a way to
produce an IO object f whose .readline() (or other special method) does
this and has an optional prompt argument? The OP's code would become

with open_terminal('/dev/tty') as f:
    name = f.readline(prompt='Name? ')

It seems to me that changing the rather specialized input() function is
wrong in both cases. For me input() is just a short way to read from the
standard input, usually interactively – the same way print is a short way
to write to the standard output. IIRC there was even proposal to remove
input() in favor of direct use of sys.stdin.readline() at time of Python
3000 redesign.

Regards, Adam Bartoš
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170929/a301cf04/attachment-0001.html>


More information about the Python-ideas mailing list