how is the readline set_completer function suppose to work
Peter Otten
__peter__ at web.de
Wed May 8 10:08:56 EDT 2019
sinbad.sinbad at gmail.com wrote:
> Below i was expecting the test() function to be called, but it doesn't. Am
> i doing it wrong? By the way i'm running version 2.7.10 on a mac.
>
> $python
>
>>>> import readline
>>>> def test():
> ... print("test")
> ...
>>>> test()
> test
>>>> print(help(readline))
>
> None
>>>> readline.set_completer(test)
>>>> raw_input()
>
> '\t\t\t'
>>>>
You need to tell readline that you want the tab key to complete with
parse_and_bind(), and you need a complete function with the right signature:
>>> import readline
>>> def test(prefix, index):
... try: return [s for s in "foo forge fun".split() if s.startswith(prefix)][index]
... except IndexError: return None
...
>>> readline.set_completer(test)
>>> readline.parse_and_bind("tab: complete")
>>> raw_input()
f
foo forge fun
fo
foo forge
forge
'forge'
More information about the Python-list
mailing list