'enable auto-completion in Python input prompt

Is there a way to, using the modules cmd or readline, get smart completion when reading an input string that only matches a specific set of values?

For instance:

read_from_list(prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"])

will create prompt

Name:

If I enter

Ad

and press complete (typically via Tab-key) I get

Adam

As a bonus it shouldn't even be possible to enter a string other than Adam, Bert or Cesar together with a set of all their prefixes.

Update: In essence I want a Python 3 variant of Emacs's completing-read: https://www.gnu.org/software/emacs/manual/html_node/elisp/Minibuffer-Completion.html



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source