Reputation: 418
I created a Python project in Pycharm which contains multiple Python files. As of just now, I need to create a run configuration for each Python file in my project, even though they're all the exact same - with the exception of the script.
This seems unnecessary and laborious and I would love to just use one run configuration for multiple Python files.
That said, I'm a novice Python programmer just getting started and so still unfamiliar with large parts of the language.
My Project Files:
My Run Configuration - Used for all Python files:
Some Research Carried Out
I've searched for a solution and explanation to this, but have been unable to find anything. Some of the places I've tried:
I hope there is sufficient detail here, if not I'd be happy to elaborate.
Upvotes: 9
Views: 2677
Reputation: 11
I was facing a similar situation when I started competitive programming. In my case I wanted to redirect my Test Cases from an input.txt
file rather than manually typing the test cases for every run of my code. Using the above solution was not feasible, as I would need to manually change the Script
Path and Redirect Input
path in the Run Configuration window for every script I was running.
So what I wanted was, one run configuration, that would run all the scripts with Redirect Input
path being set to input.txt
.
To do that,
I created a main.py
file with the following content:
import sys
if __name__ == '__main__':
fname = sys.argv[1]
exec(open(fname).read())
This main.py
file is going to run my other python scripts.
Created this run configuration for the main.py
file.
Now, every time I needed to run any code, with the code window open, ran this configuration, which actually executed main.py
with current file name passed as its argument, which would then also take the inputs redirected from input.txt
.
Hope this helps you or anyone trying to run multiple python scripts with a single run configuration in PyCharm
.
Upvotes: 0
Reputation: 964
If those files are independent and you have nothing specific to them, then I see two simple ways of running them:
Upvotes: 5