Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“增强Python命令模块”;“帮助”;打印输出_Python - Fatal编程技术网

“增强Python命令模块”;“帮助”;打印输出

“增强Python命令模块”;“帮助”;打印输出,python,Python,我正在使用Python的cmd模块为应用程序创建自定义交互式提示。现在,当我在提示下键入help时,它会自动显示我的自定义命令列表,例如: [myPromt] help Documented commands (type help <topic>): ======================================== cmd1 cmd2 cmd3 [myPromt]帮助 文档化命令(键入帮助): ===================================

我正在使用Python的
cmd
模块为应用程序创建自定义交互式提示。现在,当我在提示下键入
help
时,它会自动显示我的自定义命令列表,例如:

[myPromt] help

Documented commands (type help <topic>):
========================================
cmd1 cmd2 cmd3
[myPromt]帮助
文档化命令(键入帮助):
========================================
cmd1 cmd2 cmd3
我想用一些文本来补充这一点,解释可以在提示时使用的键盘快捷键,例如

[myPromt] help

Documented commands (type help <topic>):
========================================
cmd1 cmd2 cmd3

(use Ctrl+l to clear screen, Ctrl+a to move cursor to line start, Ctrl+e to move cursor to line end)
[myPromt]帮助
文档化命令(键入帮助):
========================================
cmd1 cmd2 cmd3
(使用Ctrl+l清除屏幕,Ctrl+a将光标移动到行首,Ctrl+e将光标移动到行尾)
是否有人知道在发出“帮助”命令时使用工具插入和修改打印的锅炉板文本的方法?

如何使用:


如果需要将自定义消息放在普通帮助消息之后,请使用
do\u help

import cmd

class MyCmd(cmd.Cmd):
    def do_cmd1(self): pass
    def do_cmd2(self): pass
    def do_cmd3(self): pass
    def do_help(self, *args):
        cmd.Cmd.do_help(self, *args)
        print 'use Ctrl+l to clear screen, Ctrl+a ...)'

d = MyCmd()
d.cmdloop()
输出:

(Cmd) ?

Undocumented commands:
======================
cmd1  cmd2  cmd3  help

use Ctrl+l to clear screen, Ctrl+a ...)
完美的我使用了do_help()覆盖,效果非常好,谢谢!
import cmd

class MyCmd(cmd.Cmd):
    def do_cmd1(self): pass
    def do_cmd2(self): pass
    def do_cmd3(self): pass
    def do_help(self, *args):
        cmd.Cmd.do_help(self, *args)
        print 'use Ctrl+l to clear screen, Ctrl+a ...)'

d = MyCmd()
d.cmdloop()
(Cmd) ?

Undocumented commands:
======================
cmd1  cmd2  cmd3  help

use Ctrl+l to clear screen, Ctrl+a ...)