If you place
import code
code.interact(local=locals())
at any point in your script, python will instantiate a python shell at exactly that point that has access to everything in the state of the script at that point. ^D exits the shell and resumes execution past that point.
You can even modify the state at that point from the shell, call functions, etc.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…