Python:调试时如何保存当前变量? [英] Python: How to save current variables while debugging?
问题描述
我在python中有一个常见的调试问题(pycharm IDE如果重要)
I have a general debugging question in python (pycharm IDE if it matters)
说我有代码,由2个块组成:
Lets say I have code which is made up of 2 blocks:
Code block 1 (takes very long to run)
Code block 2 (where I want to debug)
有没有办法在运行代码块1的最后保存当前变量,以便我可以倒回那些变量状态和调试从那里,没有重新运行整个脚本来重新计算那些变量?
Is there a way to save the current variables at the end of running code block 1, so that I can "rewind" back to those variables states and debug from there, without having the re-run the entire script to recompute those variables?
推荐答案
我不知道这个问题的一般解决方案。但是可以使用用于序列化对象的各种方法来构建应用程序特定的解决方案,但是我建议泡菜对于这个问题。
I am unaware of a general solution to this problem. But an application specific solution can be constructed using various methods for serializing objects, but I would suggest pickle for this problem.
像其他一样,有一个小例子已经在 SO 。
Like so much else, there is a small example already on SO.
这篇关于Python:调试时如何保存当前变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!