I'm trying to setup a pre populated input in my python script. Essentially what I'm trying to do is create an input that if called will be pre-populated with a variable set earlier in the script (usernames and IP addresses). I've found the following post (Is it possible to prefill a input() in Python 3's Command Line Interface?) with a suggestion but for some reason when I run it nothing happens.
import readline
def input_with_prefill(prompt, text):
def hook():
readline.insert_text(text)
readline.redisplay()
readline.set_pre_input_hook(hook)
result = input(prompt)
readline.set_pre_input_hook()
return result
Anything I pass to the prompt variable works but nothing seems to happen with the text variable the input remains blank. If I run the script in the terminal then I can see the text variable but its placed before the prompt and is uneditable which defeats the purpose of what I'm trying to do. Which is allow the user to edit the username or IP they've entered if login fails.
I'm using Python 3.8 on Manjaro Linux. Any help would be much appreciated.