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

Serhiy Storchaka storchaka at gmail.com
Fri Sep 29 08:19:49 EDT 2017


29.09.17 14:40, Steven D'Aprano пише:
> 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.

Well, I forgot about a flush(). Now this is just a three-liner.

     fout.write('Name? ')
     fout.flush()
     name = fin.readline()

> There's no support for arrow keys, even when readline is available:
> 
> My name^[[D^[[C^[[D

Did you check that arrow keys are supported with the proposed PR?



More information about the Python-ideas mailing list