debugging in IPython

N

Nick Matzke

This is a general question, but maybe there is some obvious solution
I've missed.

When I am writing code, I have a main script that calls functions in
another .py file. When there is a bug or crash in the main script, in
IPython I can just start typing the names of variables etc. to see what
they contained at the point where the script crashed.

However, if the bug is in a function I've called from the main script,
the crash dialog will indicate the function, line of code, etc. where
the crash occurred. However, the only variables I can access at the
IPython prompt are those used in the main script.

Is there any way to access the variables in those sub-functions after a
crash, in IPython or something similar? The only other option is
pasting all the code from each function into the IPython manually, or
adding print lines throughout the relevant sub-functions. This is
doable but extremely tedious when the crash occurred 5 functions deep,
or at some unknown point within a for loop.

Any help much appreciated!

Cheers!
Nick


--
====================================================
Nicholas J. Matzke
Ph.D. student, Graduate Student Researcher
Huelsenbeck Lab
Center for Theoretical Evolutionary Genomics
4151 VLSB (Valley Life Sciences Building)
Department of Integrative Biology
University of California, Berkeley

Lab websites:
http://ib.berkeley.edu/people/lab_detail.php?lab=54
http://fisher.berkeley.edu/cteg/hlab.html
Dept. personal page:
http://ib.berkeley.edu/people/students/person_detail.php?person=370
Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html
Lab phone: 510-643-6299
Dept. fax: 510-643-6264
Cell phone: 510-301-0179
Email: (e-mail address removed)

Mailing address:
Department of Integrative Biology
3060 VLSB #3140
Berkeley, CA 94720-3140

-----------------------------------------------------
"[W]hen people thought the earth was flat, they were wrong. When people
thought the earth was spherical, they were wrong. But if you think that
thinking the earth is spherical is just as wrong as thinking the earth
is flat, then your view is wronger than both of them put together."

Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer,
14(1), 35-44. Fall 1989.
http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm
====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top