How can I run my currently edited file in a PyCharm console in a way that I can type into the command line afterwards?


I want this so I can retain the command line history after repeated runs, and to paste lines from the console into tests etc. Exactly like in IDLE.

[I realize this question is basically a duplicate of Running a module from the pycharm console. But the question there is not answered satisfyingly (for me), and my lack of reputation does not let me comment there, since I just signed up.]

Asked By: user3107036



Select the code fragment or the entire file, then use Execute Selection in Console from the context menu.

Answered By: CrazyCoder

Shift+Alt+Ewould execute the selected code.

Answered By: user3507584

For anyone still having this problem: Go to the Run/Debug menu, choose Edit Configuration, check the box ‘Show command line’ this will enable you to enter parameters in the console at the >>> prompt and test your function.

Edit: To make this change apply to all your .py files (as this check box only applies to the current file you’re working on) go to: Edit configuration, in the pop up you will see a menu tree on the left, select Defaults, then Python, then check the ‘Show command line’ box, this will make it the default setting whenever you open a .py file, (this feature should really be on by default!)

Answered By: Rampkins
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.