Maltysen Maltysen - 1 year ago 57
Python Question

Setting completekey=None removes up-arrow functionality

I'm trying to write a small REPL using the

library in Python. One of the features that it provides is automatic tab completion, which I do not want.

Luckily, the docs mention "If completekey is not None and readline is available, command completion is done automatically." So I set
when I instantiated my
subclass, which worked.

However, the main functionality of the
module, the use of
which gives support for up-arrow history, was also disabled, and now I'm back to

Why is this happening, and is there a solution?

Answer Source

The readline module is only imported if completekey has a non-None value. It looks like the only way to use readline and disable completion is to specify a do-nothing completer.

class CmdSubclass(Cmd):
    # Other configuration
    # ...

    def complete(self, *args):
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download