Skip to main content
 首页 » 编程设计

python之自定义 Python Cmd 模块默认错误消息

2025年02月15日9birdshome

我正在构建命令行实用程序,使用 python cmd 模块。现在我想更改默认的 *** Unknown syntax: ds 像这样 [-] Unknown command: ds.

有可能改变吗?

请您参考如下方法:

是的,您只需要覆盖 default()方法:

class MyCmd(cmd.Cmd): 
    def default(self, line): 
        self.stdout.write('[-] Unknown command: %s\n' % (line,))