1
我用下面的代码文本完成:完成者与国际字符
class MyCompleter(object): # Custom completer
def __init__(self, options):
self.options = sorted(options)
def complete(self, text, state):
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
try:
return self.matches[state]
except IndexError:
return None
def setCompleter(listOfItems):
readline.parse_and_bind('tab: complete')
readline.parse_and_bind('set editing-mode vi')
completer = MyCompleter(listOfItems)
readline.set_completer(completer.complete)
的选项是从数据库中获取。当我需要完成时, 不提供包含国际字符和的选项。 我可以自定义代码以提供包含变音符号的选项吗?
Python版本您使用的? –