在每次cmdloop迭代结束时调用函数(cmd模块)

2024-09-28 13:31:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用cmd模块构建一个小的命令行应用程序,并尝试在每个cmd循环的末尾调用一个函数。你知道吗

我找到的唯一方法是重写cmdloop,并在其中添加我的函数调用。 有没有更简单/更干净的方法?你知道吗


Tags: 模块方法函数命令行cmd应用程序末尾函数调用
1条回答
网友
1楼 · 发布于 2024-09-28 13:31:55

实现the ^{} method

Cmd.postcmd(stop, line)

Hook method executed just after a command dispatch is finished. This method is a stub in Cmd; it exists to be overridden by subclasses. line is the command line which was executed, and stop is a flag which indicates whether execution will be terminated after the call to postcmd(); this will be the return value of the onecmd() method. The return value of this method will be used as the new value for the internal flag which corresponds to stop; returning false will cause interpretation to continue.

在执行每个cmd之后,将对对象调用该方法(从cmd.Cmd继承)。只要您从这个方法返回False,执行就会继续。你知道吗

相关问题 更多 >

    热门问题