pdb有没有初始化文件(类似于.gdbinit)?

Is there an initialization file (similar to .gdbinit) for pdb?

我是 python 的新手,我习惯使用 gdb。我想知道是否有一种方法可以为 pdb 提供一个类似于 .gdbinit 的初始化文件。主要原因是因为我想定义函数,这样我就不必在每次启动 pdb 时都键入 import os; os.system('clear')(例如 python -m pdb somescript.py

是的,根据documentation

If a file .pdbrc exists in the user’s home directory or in the current directory, it is read in and executed as if it had been typed at the debugger prompt. This is particularly useful for aliases. If both files exist, the one in the home directory is read first and aliases defined there can be overridden by the local file.

请注意,您键入的命令就像您在 pdb 解释器中键入的一样,所以它可以让您完成您想要的。

是的,.pdbrc

您可以使用 Ned's .pdbrc file 作为起点。很有用。