When I am running inside an interactive session (in my case ipython
), and am currently inside a debugger (ipdb
or pdb
) I would like to be able to put a variable into the main interactive namespace from within the debugging namespace.
This is useful if my code crashes, but has already done significant work, some of which is salvageable to save time (for example, loading data from disk).
so what I'd like is something like this, for example:
>>> run -m my.module
loading data from disk...
done loading data.
processing data...
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
...
-> here something goes wrong during processing, but the loading of data worked fine... so I'd go into the debugger to check out what happened, and to see the loaded_data
:
>>> debug
ipdb> len(loaded_data)
100000
-> Then I would like to be able to save this variable to the interactive namespace for use outside the debugger, like so:
ipdb> save_to_interactive('loaded_data')
ipdb> exit
>>> len(loaded_data)
100000
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…