Issue
I have a simple Python program which uses a read-eval-print loop to read user input via raw_input
and then print things to the screen. I would like to keep a history of previous inputs and cycle through them when the user presses keyup or keydown, similar to the Python interpreter or to the bash shell. How can I do this in Python?
Someone asked for sample code:
while True:
user_input = raw_input()
print user_input + " this many hats!!!"
I'd like to make it so a keyup puts the last line of input on the command line. The first answer given, use the readline
module, is likely the best.
Solution
Try using the readline
module. If your platform supports readline, simply importing the module should make its functionality available via the raw_input
prompt.
Answered By - Josh Rosen Answer Checked By - Dawn Plyler (WPSolving Volunteer)