Running a single line of code in PyCharm

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 ().

This seems like a cumbersome way to write code. Is there a way to run a single like of code like in RStudio?

1

5 Answers

ALT+SHIFT+E will execute in console.

CTRL+SHIFT+A will let you search for hotkeys.

6

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

2

Currently the best option:

  1. First download the free plugin Python Smart Execute

  2. Use the key combination OPTION + SHIFT + A

  3. 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

1

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: ()

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like