input vs. readline

John Nagle nagle at animats.com
Fri Jul 8 19:17:34 EDT 2016


   If "readline" is imported, "input" gets "readline" capabilities.
It also loses the ability to import control characters.  It doesn't
matter where "readline" is imported; an import in some library
module can trigger this.  You can try this with a simple test
case:

   print(repr(input()))

as a .py file, run in a console.  Try typing "aaaESCbbb".
On Windows 7, output is "bbb".  On Linux, it's "aaa\x1bbbb".

So it looks like "readline" is implicitly imported on Windows.

   I have a multi-threaded Python program which recognizes ESC as
a command to stop something.  This works on Linux, but not on
Windows.  Apparently something in Windows land pulls in "readline".

   What's the best way to get input from the console (not any
enclosing shell script) that's cross-platform, cross-version
(Python 2.7, 3.x), and doesn't do "readline" processing?

(No, I don't want to use signals, a GUI, etc.  This is simulating
a serial input device while logging messages appear.  It's a debug
facility to be able to type input in the console window.)

				John Nagle



More information about the Python-list mailing list