[Python-ideas] allow overriding files used for the input builtin
Steven D'Aprano
steve at pearwood.info
Fri Sep 29 07:40:04 EDT 2017
On Fri, Sep 29, 2017 at 01:45:05PM +0300, Serhiy Storchaka wrote:
> Why not use just the following two lines?
>
> f.write('Name? ')
> name = f.readline()
Because the two-liner doesn't do what input() does. Testing it at the
interactive interpreter gives me:
py> def myinput():
... sys.stdout.write("Name? ")
... return sys.stdin.readline()
...
py> x = myinput()
Steve
py> ? py>
The output isn't displayed until the input is entered, and then the
prompt messes it up.
Admittedly this isn't likely to be an issue if you're redirecting to
another file, but it demonstrates that your suggested replacement is not
equivalent to the feature request.
There's no support for arrow keys, even when readline is available:
My name^[[D^[[C^[[D
> This falls to me in the category "not every two lines of the code should
> be added as a builtin".
The built-in already exists. This is making it more useful, just like
adding file to print made print more useful.
--
Steve
More information about the Python-ideas
mailing list