斜线和蟒蛇CMD(Slash and python cmd)

2019-09-18 02:33发布

我想实现一个python CMD,使用CMD模块。 我想自动完成文件,所以我已经实现了一些方法,但是,我已经看到了从文本参数“complete_put(自我,文字,线条,begidx,endidx):”去掉所有的“/”字符。 任何人都知道为什么,我怎样才能避免这种情况? 谢谢 :)

Answer 1:

我解决了它。 只是不得不修改set_completer_delims属性。



Answer 2:

这是我使用的代码,它是基于在互联网上发现了几个例子。

import os
import cmd
import readline
class Shell(cmd.Cmd, object):
    def __init__(self):
        cmd.Cmd.__init__(self)

    def __complete_path(self, path=None):
        return ['/bin', '/boot', '/etc']

    def do_put(self,args):
        print args

    def complete_put(self, text, line, begidx, endidx):
        print text
        if not text:
            return self.__complete_path()
        return self.__complete_path(text)


文章来源: Slash and python cmd
标签: python cmd