There is a high level logic error deep within my Python script, and pdb
doesn\'t help to debug it. Is there any other way to see what is being executed after I run
I found a way to do this using excellent trace module that comes with Python.
An example how to troubleshoot module installation problem:
python -m trace -t setup.py install > execution.log
This will dump all source line of setup.py install
execution to execution.log
. I find this more useful than pdb
, because usability of pdb
command line interface is very poor.
No, there's no magic formula.
My best suggestion is to get a good IDE with a debugger, like JetBrains' PyCharm, and step through your code to see where you went wrong.
Most of the time these situations happen because you make assumptions about behavior that aren't true. Get a debugger, step through, and check your assumptions.
I would recommend using pdb. You can use
import pdb
at the top of your script, and then add the line
pdb.set_trace()
somewhere in the code where you want to trace the problem. When the script gets to that line, you will have an interactive console where you can check variable values, run your own checks, and see what is going on. You can use n
to execute the next line, or c
to continue to the next occurrence of set_trace()
. Full documentation is here: http://docs.python.org/2/library/pdb.html.
Let me know if you have any specific questions!