3

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.

Kevin Burke
  • 61,194
  • 76
  • 188
  • 305

2 Answers2

9

Try using the readline module. If your platform supports readline, simply importing the module should make its functionality available via the raw_input prompt.

Josh Rosen
  • 13,511
  • 6
  • 58
  • 70
0

For standard input function also works. No configuration needed. Just import readline.

Anton Samokat
  • 542
  • 1
  • 6
  • 15