Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 584
user3107036 Avatar asked Dec 16 '13 11:12

user3107036


People also ask

How do I run a current file 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.

How do I run a Python file from command-line?

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!

How to execute a file in PyCharm console?

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.

How to run current script in PyCharm 2020?

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

How do I change the name of a PyCharm shell script?

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:

How do I launch PyCharm from the toolbox app?

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:


2 Answers

Shift+Alt+Ewould execute the selected code.

like image 142
user3507584 Avatar answered Sep 21 '22 20:09

user3507584


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

like image 44
CrazyCoder Avatar answered Sep 19 '22 20:09

CrazyCoder