In previous versions of Spyder, you can select lines in the editor, and only run those selected lines.
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?
In Spyder, you can organize your code as runnable cells.
Use the the pattern # In[]
or #%%
to define the start of a cell. You could also have child cells by adding additional percent signs %
.
The hotkey for running a the line at which the cursor is, or the currently selected lines in Spyder 4 is F9. Ctrl+Enter will run the current cell. You can read more about cells in Spyder here. Basically, these are blocks of code that can be defined in the editor using a specific syntax within the code, and can be run independently by Spyder and other IDEs.
Incidentally, Ctrl+Enter is the keyboard shortcut for running the current line in R Studio, not Spyder, which may be where you got it confused.
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