Python cmd.cmd 按 ctrl+D 退出

标签 python

如何在发出 ctrl+D 命令时使 CmdModule 退出? 默认情况下,当您发出 ctrl+C 命令时,我们会退出 shell,但在发出 ctrl+D 命令时不会退出。

最佳答案

来自https://pymotw.com/3/cmd/ ,看起来我们只是实现了:

def do_EOF(self, line):
        return True

在主类中,这个 do_EOF 函数处理这个 ctrl+D 输出。

编辑:

请注意,如果您键入命令“EOF”,这也会导致它退出。它还会导致“EOF”显示在您的 help 命令中。

关于Python cmd.cmd 按 ctrl+D 退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50339501/

相关文章:

python - 使用 Python 3 从 Windows 进行 SSH 和 SCP

python - 设置子图的背景颜色

python - 如何为 C 函数使用 LAPACK 库的 Python 编译 C 扩展?

Python SimpleHTTPServer 不断下降,我不知道为什么

python - 双下划线__在python中是什么意思?

python - Python中dict对象的联合

python - 在 MacOS Sierra 中的 Apache 上执行 python 脚本

Python MySql API 连接器 : How to disable logging

python - Keras 密集输出层形状错误

python - 在 python pandas 中获取剩余聚合列作为两列分组的列表