[IPython-user] how to debug a temp file

danny shevitz danny_shevitz at yahoo.com
Wed May 18 11:39:04 CDT 2005


So I can't figure out how to debug an interactive session elegantly. 

I have an ipython session where I have been doing some useful stuff. I
have been using magic edit a lot. The useful script now resides in a
temp file. But alas, there is a bug. I need to debug. I suspect the bug
is in a function I call, so I want to break there. 

I'm stuck how to do this elegantly in ipython. Here are the options as
I know them.
1) Put 1/0 in the temp file. Run with Pdb on. Unfortunately, this
doesn't work because I want to break at the beginning of the routine,
and if I throw an exception, I can't continue past it (at least I don't
know how)
2) Save the temp file to a permanent file and then use magic run -d,
but I don't really want to save the file explicitly. This works fine,
but I'm in a version controlled environment and then I have junk files
that aren't versioned... So I don't like this.
3) use _n to get the output of the history and then explicitly do a pdb
import, pdb.run(_n). This works, but isn't great since the top level is
 a single string and so setting breaks is impossible.

So that's it. I'm stuck for an elegant way. My suggestion is to add a
new flag to the magic run (-t, for temp) which runs the last tempfile.
This way hopefully, you could use a syntax like run -d -t and this
would do exactly what I want. In principle you could add history
numbers for which tempfile to debug, but using ed _n will make a new
one with the desired state. In fact you could even have run -d default
to the last tempfile without an explicit filename given. I don't know
if ipython tracks tempfile names though.

I guess in summary, ipython has magic for profiling and timing
interactive code, but debugging is only accessible via explicity pdb
calls or else the run -d but that requires a named file, which
completely abuses the notion of ipython being an interactive
environment. Any comments or suggestions.

D
 


		
__________________________________ 
Do you Yahoo!? 
Read only the mail you want - Yahoo! Mail SpamGuard. 
http://promotions.yahoo.com/new_mail 




More information about the IPython-user mailing list