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

16,054

Solution 1

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

Solution 2

Shift+Alt+Ewould execute the selected code.

Solution 3

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!)

Share:
16,054
user3107036
Author by

user3107036

Updated on June 11, 2022

Comments

  • user3107036
    user3107036 about 2 years

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