Reputation: 676
I am currently debugging code using Python. I have not been using Python for a while. I put some breakpoints on a variable which is an integer. Let's say this variable is X = 10
. How can I:
X+2
and get the result?Upvotes: 8
Views: 3145
Reputation: 13619
As noted in the comments, there are many possible IDEs you can use with Python. The original question was specifically about Eclipse and so my answer focuses on a solution using that IDE. Other solutions are possible if you prefer a different environment...
First off, you need to sort out which plug-in you use for eclipse. You have a few options as you can see on the python wiki. It looks like PyDev is more popular, but you could pick others.
Assuming you go for PyDev, you can use the watch facility as described here to evaluate any expression. Alternatively you can use the console debugger to evaluate code directly in the debugger.
EDIT: As per the comments, you can also open the Expressions window using Window > Show View > Other > Debug > Expressions
. This is the same window as used for the watch facility and the contents can be edited directly.
Upvotes: 3
Reputation: 1241
ipdb
is a handy tool for python debugging:
ipdb exports functions to access the IPython debugger, which features tab completion, syntax highlighting, better tracebacks, better introspection with the same interface as the pdb module.
To install ipdb, simply run pip install ipdb --user
in your shell.
To set breakpoint, add import ipdb; ipdb.set_trace()
before the line where you want to jump into the debugger. E.g.:
import ipdb; ipdb.set_trace()
X=10
Once you run your program python myfunc.py
, an IPython-like interactive shell will be triggered and you can run python commands in it. E.g.:
ipdb> p X
10
ipdb> X+2
12
Here is a simple tutorial: An Introduction to Python Debugging
Upvotes: 0
Reputation: 1881
Try opensource, free VS Code (with Python plugin). It has a slick intellisense feature and you can watch, inspect the variables, debug them. The editor is node.js based and can work in every platform. Eclipse is overkill for python development IMHO.
Upvotes: 0
Reputation: 468
I don't think you can do this purely in Eclipse, not without extensive plugins. However, there are some very good python debugging tools out there.
If you're willing to get your hands dirty, the builtin python debugger pdb does everything you want and more. Import pdb
, pdb.set_trace()
where you want to break, and you step into an interactive debugger that's very familiar if you've used gdb
before.
If you want to use something more IDE focused, I recommend Immunity Debugger. It's really rather good, and has a lot of documentation. This might be a little more than you're looking for though.
Upvotes: 1
Reputation: 1227
I'm sure everyone has their own opinion, but I find the python tools for Eclipse quite complex. If you aren't tied to an Eclipse IDE, try PyCharm. It has very good tools for doing exactly what you want, and many tutorial videos. This video shows you how to do exactly what you have requested: https://www.youtube.com/watch?v=QJtWxm12Eo0
Upvotes: 1