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.]
The key combination you are looking for is Ctrl + Shift + F10 . This will run the current script with current being the one displayed in the viewer. Alt+Shift+F10 in PyCharm 2020.3.
To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World!
Since PyCharm 2017.3 there is an action "Execute File in Console" which does exactly that. You can find it with Find action (Ctrl + Shift + A) and execute currently selected file. Hello! Thanks for your answer! Can't seem to find this command. Looking threw the key map and "Find action...", the "Execute File in Console" does not exists.
I just forgot that we can right click on tabs in pycharm. The key combination you are looking for is Ctrl + Shift + F10. This will run the current script with current being the one displayed in the viewer. Alt+Shift+F10 in PyCharm 2020.3. You can right click on the file, and then run Run 'filename'.
At the bottom, change the Shell script name field. By default, the Toolbox App puts shell scripts in a directory from the system PATH environment variable, so you can run the name of the script as a command to launch PyCharm from any working directory. The launcher script accepts commands, options, and other arguments to modify its behavior:
By default, the Toolbox App puts shell scripts in a directory from the system PATH environment variable, so you can run the name of the script as a command to launch PyCharm from any working directory. The launcher script accepts commands, options, and other arguments to modify its behavior:
Shift+Alt+E
would execute the selected code.
Select the code fragment or the entire file, then use Execute Selection in Console from the context menu.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With