Is it possible to execute ONLY the highlighted code in a Jupyter notebook cell? This is possible in Spyder and RStudio.
I find this to be quite useful for trouble-shooting code as you write.
If a cell contains:
a=13
b=17
c=42
a=a*c
I'd like to be able to highlight and run only the desired lines (e.g. variable assignmemnts), but not the final line.
I use this frequently in Spyder and RStudio, would love to do in Jupyter as well. I find I am constantly splitting and re-combining cells in order to troubleshoot a single line of code, where for example, I've indexed into something incorrectly. Highlighting and printing the variable allows me to see what I've actually assigned it to be and is throwing an error, vs. what I had intended.
Capturing Output With %%capture IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.
Alt + Enter run the current cell, insert below.
There is no such thing in Jupyter as 'highligh and run'. At least I am not aware of it.
Run the cell after commenting the other lines out using CTRL + /, split cells and execute only the chosen ones or use a debugger (e.g. pudb, it works in Jupyter) to change variables values on the fly (while debugging).
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