stop program and start interactive interpreter

Dave Reed drlinux at columbus.rr.com
Sat Oct 11 18:28:00 EDT 2003


On Saturday 11 October 2003 15:14, Jp Calderone wrote:
> On Sat, Oct 11, 2003 at 02:28:00PM -0400, Dave Reed wrote:
> > 
> > I seem to remeber reading somewhere there was a statement you could
> > put in your python program to stop its execution and start the
> > interactive interpreter at that point (and then you could change the
> > value of some variables and continue executing). Am I having 
delusions
> > or is there a way to do this?
> > 
> 
>   One way, perhaps not the one you are thinking of, is:
> 
>     import pdb; pdb.Pdb().set_trace()
> 
>   Jp

I think that's what I remember reading before (the set_trace looks
familiar). It almost works the way I would think.

For this simple example, it does stop and 

import pdb

def main():

    x = 2
    print x
    pdb.Pdb().set_trace()
    print x
    z = y
   
main()

but it doesn't appear to allow variables to be changed or added. Or am
I not using it correctly?

python a.py
2
> /home/dreed/a.py(8)main()
-> print x
(Pdb) print x
2
(Pdb) x = 5
(Pdb) print x
2
(Pdb) y = 3
(Pdb) continue
2
Traceback (most recent call last):
  File "a.py", line 11, in ?
    main()
  File "a.py", line 9, in main
    z = y
NameError: global name 'y' is not defined

Thanks,
Dave







More information about the Python-list mailing list