python - 如何在程序中启动 python 控制台(以便于调试)?

标签 python console debugging interpreter

经过多年的 Matlab 编程研究,我想念我可以通过交互式控制台暂停程序执行并检查变量、绘图、保存/修改数据等,然后恢复执行的方式。

有没有办法在 python 中做同样的事情?

例如:


   # ... python code ...
   RunInterpreter
   # Interactive console is displayed, so user can inspect local/global variables
   # User types CTRL-D to exit, and script then continues to run
   # ... more python code ...

这将使调试变得容易得多。非常感谢建议,谢谢!

最佳答案

使用 pdb图书馆。

我将此行绑定(bind)到 <F8>在 Vim 中:

import pdb; pdb.set_trace()

这会让你进入 pdb控制台。

pdb console 与标准 Python 控制台完全不一样......但它会做大部分相同的事情。另外,在我的 ~/.pdbrc ,我有:

alias i from IPython.Shell import IPShellEmbed as IPSh; IPSh(argv='')()

这样我就可以从 pdb 进入一个“真正的”iPython shell与 i命令:

(pdb) i
...
In [1]:

关于python - 如何在程序中启动 python 控制台(以便于调试)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4511763/

相关文章:

python - 当父记录存在时,如何在 django rest 框架中的子序列化程序中设置外键值

shell - GDB:backtrace命令的格式:在另一个shell/ssh中运行时将帧行分为几行

image - 链接文件无效

Android Eclipse 无法调试

.net - SSIS 中的调试

python - 将时间戳转换为 str 值 python pandas dataframe

Python 脚本失败,出现 ('Connection aborted.' , ConnectionResetError(104, 'Connection reset by peer' ))

java - CTRL-C如何与Java程序一起工作

c# - 如何从 C# 中的 DataRow 读取字节数组?

python - 使用 ORB 的 OpenCV 图像对齐