Suppose I have two python scripts methods.py and driver.py.
methods.py has all the methods defined in it, and driver.py does the required job when I run it.
Let's say I am in a main directory with the two files driver.py and methods.py, and I have n subdirectories in the main directory named subdir1,subdir2,...,subdirn. All of these subdirectories have files which act as inputs to driver.py.
What I want to do is run driver.py in all these subdirectories and get my output from them, without writing driver.py to disk.
How should I go about this? At the moment, I am using the subprocess module to
- Copy driver.py and methods.py to the subdirectories.
- Run them.
The copying part is simple:
import subprocess
for i in range(n):
cmd = "cp methods.py driver.py subdir"+str(i)
p = subprocess.Popen(cmd, shell=True)
p.wait()
#once every subdirectory has driver.py and methods.py, start running these codes
for i in range(n):
cmd = "cd subdir" + str(i) +" && python driver.py"
p = subprocess.Popen(cmd, shell=True)
p.wait()
Is there a way to do the above without using up disk space?