Similarly to these (very useful!) two functions:
"Run current cell" "Run selection or current line"
Is it possible to do this with debugging? I dont want to start from the top of my large script files every time I debug.
I'm using Spyder version 3.2.4
In Spyder 4.0.1, the keyboard shortcut for 'run cell' is set to Ctrl+Return but for 'run selection' it is set to F9. You can use F9 to run a selection or if you prefer to use Ctrl+Return, you can go to Tools -> Preferences -> Keyboard shortcuts. Search for 'run selection', double click and set Ctrl+Return as the 'New shortcut'
If there is a breakpoint present in the file you're trying to debug, then Spyder enters in debug mode and continues until the first breakpoint is met. If it's present in another file, then you still need to press first Debug and then Continue. IPdb is the IPython debugger console.
What we provide now is what people coming from Matlab would expect from a debugger, i.e. something that works like IPython and lets you inspect and plot variables at the current breakpoint or frame. If there is a breakpoint present in the file you're trying to debug, then Spyder enters in debug mode and continues until the first breakpoint is met.
In Spyder 4, when you select lines and press Ctrl + Enter it executes runcell (0, '/your/dir/file.py') which runs the whole code. How can I run just the lines which I have selected?
If you are using IPython as your interpreter, you can use the magic %pdb
in IPython to automatically start pdb
when an error is encountered.
Then you can "Run current cell" and break out into the debugger when you need to.
For example I have a simple script:
my_var = 4
raise ValueError
Now, in the IPython terminal I first run %pdb
, and then I run my script.
In [4]: my_var = 4
...: raise ValueError
Traceback (most recent call last):
File "<ipython-input-4-31dc119cb1f3>", line 2, in <module>
raise ValueError
ValueError
> <ipython-input-4-31dc119cb1f3>(2)<module>()
1 my_var = 4
----> 2 raise ValueError
ipdb>
and I have the debugger available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With