Invalid python cmd completedefault () method

Consider the following Python 2.7 script:

#!/usr/bin/python

import cmd

class T(cmd.Cmd):
    def completedefault(self, *a):
        print 'completedefault called'
        return []

t=T()
t.cmdloop()

When I expect:

I enter the character into the shell, and then click on the tab, I expect to see a printed "completed error".

What is actually going on:

I enter the character into the shell, then click on the tab and nothing happens.

Tested with Python 2.7.3.

+2
source share
1 answer

completedefaultIt is called to complete the input of a string after you enter a command for which the method is not available complete_<commandname>.

Try the following:

#!/usr/bin/python

import cmd

class T(cmd.Cmd):
    def completedefault(self, *a):
        print 'completedefault called'
        return []

    def test(self, *args):
        print "test args: ", args

t=T()
t.cmdloop()

now enter test[space] and click the tab completedefaultshould be done now.

, completenames , completedefault.

+3

Source: https://habr.com/ru/post/1534161/


All Articles