在cmd中使用帮助时如何过滤命令?
How do I filter through commands when I use help in cmd?
自从我将 cmd
导入到我的项目中后,我得到了很多不需要的命令。当我在解释器中并简单地键入 help
时,我得到了我所有的 defs 列表,以及一堆这些其他命令。有没有一种方法可以过滤这些,这样当我输入 help
时,我只会得到我所做的命令的列表,而不是任何 pre-made/external 的命令列表?
来自 cmd 模块的文档:
With no argument, do_help()
lists all available help topics (that is,
all commands with corresponding help_*()
methods or commands that have
docstrings), and also lists any undocumented commands.
您只需像这样覆盖 cmd
子类中的 do_help()
方法:
def do_help(self, arg):
"""Provide help information"""
# if arg is present, print help for specific function
# otherwise print general help message
自从我将 cmd
导入到我的项目中后,我得到了很多不需要的命令。当我在解释器中并简单地键入 help
时,我得到了我所有的 defs 列表,以及一堆这些其他命令。有没有一种方法可以过滤这些,这样当我输入 help
时,我只会得到我所做的命令的列表,而不是任何 pre-made/external 的命令列表?
来自 cmd 模块的文档:
With no argument,
do_help()
lists all available help topics (that is, all commands with correspondinghelp_*()
methods or commands that have docstrings), and also lists any undocumented commands.
您只需像这样覆盖 cmd
子类中的 do_help()
方法:
def do_help(self, arg):
"""Provide help information"""
# if arg is present, print help for specific function
# otherwise print general help message