How to run code selection in Spyder without changing the active window to IPython console?

Viewed 13433

This is mostly a question regarding work-flow in Spyder, and not a pure programming question. If anyone thinks it has no place here, then please let me know and I'll remove it.

Here we go:

I'm running Spyder on a Windows 64-bit operating system. The interaction between the Spyder IDE and IPython console depends on how you choose to run your code, and I would like to specify how this interaction works.

Among several options to run parts of the code, the difference between the following two is what puzzles me:

Option 1 - Select parts of the code and hit F9

This runs the selected code. No surprise there. Hit F9 again, and the same selection is executed once more. enter image description here

Option 2 - Run the same selection using Cells (#%%) and Ctrl+Enter

The code is run just like before. But hit Ctrl-Enter again, and nothing happens. Probably because the IPython console now is the active window. enter image description here

I would like to find some way of changing this so I can use Ctrl+Enter and run the cell contents multiple times without having to make the Spyder IDE the active window by manually clicking on it. I don't know if this is possible at all. Googling and messing around in the settings under Run / configure and Tools / Preferences has so far been useless.

Thank you for any suggestions!

P.S

In case you're wondering why this is such a big deal to me, I'm rendering multiple charts and exporting them to Power Point with minor changes each time the code is run. This way, new parts of the charts (lines, textboxes, etc) are revealed when I'm working my way through a finished Power Point presentation. And for my basic data science needs, this has turned out to be a pretty much optimal work-flow. Except, of course, that I have to manually select the Spyder IDE each time I run different selections of the code.

2 Answers

In the latest spyder version, the keyboard shortcut to run the highlighted lines of code is F9 but it doesn't seem to work.

Go change it from TOOLS>>PREFERENCES>>KEYBOARD SHORTCUTS then double click on any shortcut you want to change and change with your shortcut. But be very careful if you used the same shortcut that is used for any other work then for that it will remove.

I changed the shortcut for 'run selection' from F9 to ctrl + Enter

in Option 2, you should use Shift+Enter instead

Related