Posted on 16th September 2024|49 views
Is it possible to make one python file to run another?
Posted on 16th September 2024| views
There are various methods to make one python file to run another they are:
Method 1:
Utilize it as a module. import the file you need to run also run its functions. For instance, say you require to import fileY.py inside fileX.py, allowing the files are within the same directory, within fileX you would write like this:
import fileY
Now within fileX, you can call any function you want within fileY like:
fileY.some_func()
Method 2:
Use exec command:
execfile('file.py')
Method 3:
We can spawn any new process by utilizing the os.system command
os.system('python any_file.py')