I'm using input() to ask a user for a command in a Python (3) CLI script.
I'd like them to be able to press ↑ to reuse older commands. For that matter I'd like them to be able to do other basic line editing too.
I can get these features by running rlwrap myscript.py but I'd rather not have to run the wrapper script. (yes I could set up an alias but I'd like to encapsulate it in-script if poss)
Is there a library to enable this (e.g. provide a history/editing aware version of input()) or would I need to start from scratch?
I'm grateful to the answers posted as comments. I tried @furas' suggestion, and it seems to be working fine. Here's a snippet to help others who come here from a search.
promptis the main do-ing function, but you don't get any history unless you use aPromptSession. If you don't use thehistoryoption, then history is maintained in memory and lost at program exit.https://python-prompt-toolkit.readthedocs.io/en/master/index.html