[Python] Tab completion in Python's raw_input()

Discussão em 'Python' iniciado por Stack, Março 3, 2025.

  1. Stack

    Stack Membro Participativo

    i know i can do this to get the effect of tab completion in python sure.

    import readline
    COMMANDS = ['extra', 'extension', 'stuff', 'errors',
    'email', 'foobar', 'foo']

    def complete(text, state):
    for cmd in COMMANDS:
    if cmd.startswith(text):
    if not state:
    return cmd
    else:
    state -= 1

    readline.parse_and_bind("tab: complete")
    readline.set_completer(complete)
    raw_input('Enter section name: ')


    I am now interested in doing tab completion with directories. (/home/user/doc >tab)

    How would i go about doing such a task?

    Continue reading...

Compartilhe esta Página