How to have Pycharm always run "Current File"

Config: Python 3.12, Pycharm 2023.3.2, on Windows 10 Pro. I’m new to Python and have not yet completed a 62 hour tutorial on Python.

I have found that in PyCharm, when I switch projects the source file that is run seems to be the first source file in the project. How to I configure Pycharm CE to always run the current file when I click the run button?

I’m doing a tutorial where I make a new source file for each of chapter, and there are 100s of chapters.

Thank you!

Is that what you’re looking for ?

Also, a good practice in Python is to have the code you want to execute protected by an
if __name__ == "__main__": statement. See the reference documentation for rationale and further details:

When you do so, PyCharm will automatically add a run button on the left of the file editor, on which you can click to run the current file (see my screenshot below). I find it quite convenient !


1 Like

That will work. I will just change how I work. Using hotkeys probably has more advantages than what I’m doing. Thank you.

The way I work is by clicking the run button near the top of the code I’m writing, just above the source code tabs.