Reputation: 1056
As a self-taught programmer, I learned to debug using an interactive console that kept all of my variables in memory when I build /run the script. However, I noticed the overwhelming trend for debugging in IDEs (and, I suppose CLI + Editor solutions, for that matter) is to build your script in one place and provide a separate console "sandbox" type area that only keeps variables if you copy/paste your code.
How do you debug without an interactive console? Can anyone list a few debugging steps that could help me be a better programmer / debugger?
Currently, this is a very simplified version of what I do:
Upvotes: 2
Views: 472
Reputation: 41
Use print statements in between the areas of problem code... otherwise, just download a good IDE
Upvotes: 1
Reputation: 1056
It turns out that PyCharm, at least, DOES have an interactive console and the default keymapping (on Mac) is option-shift-E. Then your variables are loaded in memory. However, the suggestions above are better programming practices.
Upvotes: 0
Reputation: 28370
Use a decent python IDE - there are a lot out there and you will be able to stop at breakpoints inspect variables by hovering or adding watches and enter a context console where you can interact with your code in the context of the breakpoint.
Upvotes: 1
Reputation: 113930
you can use the q
module for this easily https://pypi.python.org/pypi/q
xyxy.py
import q
do_something()
q.d() #this will open interactive shell
def f():
do_something()
q.d() #open console here with access to all local variables of f
you can also use automated tests (builtin unittest module or nosetests or something else)
Upvotes: 1
Reputation: 526523
The best way to do this would be to write tests. That automates steps 3 through 7 for you. It also prevents regressions from occurring when you change other code.
Upvotes: 8