Running a single line of code in PyCharm
Question:
I’m coming from RStudio, so forgive my naievete.
In RStudio it’s really nice to be able to run lines by simply pressing Ctrl+Enter on the line. This sends the line of code directly to the console, which makes building functions really easy because you can work through each line to check for problems. However, in Pycharm this doesn’t appear to be a feature; instead, you select with a mouse and run code (https://www.jetbrains.com/help/pycharm/loading-code-from-editor-into-console.html).
This seems like a cumbersome way to write code. Is there a way to run a single like of code like in RStudio?
Answers:
ALT+SHIFT+E will execute in console.
CTRL+SHIFT+A will let you search for hotkeys.
You can also look into "Evaluate Expression"
option, which let’s you run code in the current scope while debugging, it’s usefull for lookups and modification in runtime.
Here is link to IDEA, but it’s the same with PyCharm:
(https://www.jetbrains.com/help/idea/evaluating-expressions.html)
It is also possible to change the key combination to your liking.
For example, if you used to work with ctrl + enter
in R, you can change it in:
File -> Settings -> Keymap - Other -> Execute selection in Python Console
Currently the best option:
-
First download the free plugin Python Smart Execute
-
Use the key combination OPTION + SHIFT + A
-
If preferred change the key combination to COMMAND + ENTER
Despite not skipping blank lines, it pretty much resembles the way you can execute code in RStudio
I know that question is about PyCharm. But for people who came here from Visual Studio Code world and wonder is there such feature. It is simple as SHIFT+ENTER.
In PyCharm 2022.2 (not sure about other versions):
File -> Settings -> Keymap -> Plugins -> Python Community Edition -> Execute Selection in Python Console -> Change this to Ctrl + ENTER
-> Accept prompt’s suggestion to clear this shortcut for other commands -> Apply
I’m coming from RStudio, so forgive my naievete.
In RStudio it’s really nice to be able to run lines by simply pressing Ctrl+Enter on the line. This sends the line of code directly to the console, which makes building functions really easy because you can work through each line to check for problems. However, in Pycharm this doesn’t appear to be a feature; instead, you select with a mouse and run code (https://www.jetbrains.com/help/pycharm/loading-code-from-editor-into-console.html).
This seems like a cumbersome way to write code. Is there a way to run a single like of code like in RStudio?
ALT+SHIFT+E will execute in console.
CTRL+SHIFT+A will let you search for hotkeys.
You can also look into "Evaluate Expression"
option, which let’s you run code in the current scope while debugging, it’s usefull for lookups and modification in runtime.
Here is link to IDEA, but it’s the same with PyCharm:
(https://www.jetbrains.com/help/idea/evaluating-expressions.html)
It is also possible to change the key combination to your liking.
For example, if you used to work with ctrl + enter
in R, you can change it in:
File -> Settings -> Keymap - Other -> Execute selection in Python Console
Currently the best option:
-
First download the free plugin
Python Smart Execute
-
Use the key combination
OPTION + SHIFT + A
-
If preferred change the key combination to
COMMAND + ENTER
Despite not skipping blank lines, it pretty much resembles the way you can execute code in RStudio
I know that question is about PyCharm. But for people who came here from Visual Studio Code world and wonder is there such feature. It is simple as SHIFT+ENTER.
In PyCharm 2022.2 (not sure about other versions):
File -> Settings -> Keymap -> Plugins -> Python Community Edition -> Execute Selection in Python Console -> Change this to Ctrl + ENTER
-> Accept prompt’s suggestion to clear this shortcut for other commands -> Apply