Complete as-you-type on command line with python

2019-05-07 00:19发布

问题:

I would like to write a small application/directory/file launcher in python. To make it fast i would like to autocomplete/autosuggest entries. But i want to display these suggestions as the user types. From what i have read about the readline module completion is only possible using a "Completion hotkey" e.g. Tab.

Any suggestions ?

Using curses with filter as suggested below does not seem to work. This minimal example clears my screen despite the call to filter():

import curses

curses.filter()
win = curses.initscr()

curses.noecho()
curses.cbreak()


while 1:
  key = win.getkey()
  win.echochar(key)
  if key == "Q":
    break

curses.endwin()

回答1:

I would try with "curses" library:

http://docs.python.org/2/library/curses.html

You have a related topic at:

How to make python autocompletion display matches?