未调用python cmd completedefault()方法 [英] python cmd completedefault() method not called

查看:62
本文介绍了未调用python cmd completedefault()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下 Python 2.7 脚本:

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()

当我期望时:

我在 shell 中输入一个字符,然后点击 Tab,我希望看到completedfault called"打印出来.

I type a character into the shell, then hit tab, I expect to see "completedfault called" printed.

实际发生了什么:

我在 shell 中输入一个字符,然后按 Tab,什么也没发生.

I type a character into the shell, then hit tab, and nothing happens.

使用 Python 2.7.3 测试.

Tested with Python 2.7.3.

推荐答案

completedefault 被调用以完成输入行 after 你输入了一个没有 的命令complete_-方法可用.

completedefault is called to complete a input line after you entered a command for which no complete_<commandname>-method is available.

试试这个:

#!/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()

现在输入 test [space] 并按 Tab,completedefault 现在应该被执行了.

now enter test [space] and press tab, completedefault should be executed now.

如果你想控制命令名称的完成,你可以使用completenames来实现,而不是completedefault.

If you want to control completion for command names, you can use completenames to do so, not completedefault.

这篇关于未调用python cmd completedefault()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆