Skip to content

Instantly share code, notes, and snippets.

Created November 9, 2021 17:59
What would you like to do?
This python program gives you auto complete suggestions of words just like command line.
import readline
import requests
class MyCompleter(object): # Custom completer
def __init__(self, options):
self.options = sorted(options)
def complete(self, text, state):
text = text.lower()
if state == 0: # on first trigger, build possible matches
if text: # cache matches (entries that start with entered text)
self.matches = [s for s in self.options
if s and s.startswith(text)]
else: # no text entered, all matches possible
self.matches = self.options[:]
# return match indexed by state
return self.matches[state]
except IndexError:
return None
url = ''
page = requests.get(url)
completer = MyCompleter(l)
readline.parse_and_bind('tab: complete')
input = input("Input: ")
print("You entered", input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment