Always import readline with Python's input
In Python, when using the built-in input()
method, always import readline
.
Readline makes for much nicer text input and supports common operations like
ctrl-A
to jump to the start of a line. Without readline, trying to type
ctrl-A
will insert a literal 0x01
byte. IPython shows the difference: in
both cases I typed This is a test.
followed by ctrl-A
.
In [1]: input()
This is a test.^A
Out[1]: 'This is a test.\x01'
In [2]: import readline
In [3]: input()
This is a test.
Out[3]: 'This is a test.'