0

I have a Python Script (which runs for about 6 days and generates multiple other files and folders).

I have multiple data-sets and need to run this Python Script on each data-set.

The data-sets have their similar names and are in completely separate locations in the drive which I shall not mixup, so no worries on this, neither can I accept an answer which involves bringing these in the same folder.

I need to run the Python Script one after the other for each Data-Set ensuring all computer resources are available during each run.

For this I thought the following code would work:

from os import system

system('python "E:\\Test and delete\\2\\MainPythonFile.py" "E:/Test and delete/1/MainPythonFile.py"')

However, only the first file is being executed!

I can find no simple solution which would enable me to execute all the files sequentially.

  • 1
    `for filepath in list_of_filepaths: system(f"python {filepath}")` seems pretty straightforward to me ... – Joran Beasley Sep 30 '22 at 06:43
  • Getting the following errors: python: can't open file 'E:\\Finalizing': [Errno 2] No such file or directory python: can't open file 'E:\\Finalizing': [Errno 2] No such file or directory – Santanu Banerjee Sep 30 '22 at 06:53
  • ahh you need `system(f'python "{filepath}"')` otherwise the spaces get interpreted wrong ... i think you can do `execfile(path_to_file)` also ... I vaguely remember ... but could be mistaken (ahh its changed slightly see https://stackoverflow.com/questions/436198/what-is-an-alternative-to-execfile-in-python-3) – Joran Beasley Sep 30 '22 at 07:03
  • This worked with no spaces in the path names... When I was using separate os.system('python "PATH\FileName.py"') and os.system('python "PATH2\FileName2.py"'), there were two simultaneous executions happening. How is this prevented here? – Santanu Banerjee Sep 30 '22 at 07:07
  • that doesnt make sense ... `system` will block until the execution completes thats just the way it works ... – Joran Beasley Sep 30 '22 at 07:08
  • from os import system system('python "D:/Test2delete/1/MainPythonFile.py"') system('python "D:/Test2delete/2/MainPythonFile.py"') Sorry! I got an new insight with the above simple code which is working correctly the way it should as your above comment. I misinterpreted this because of a specific error which Python gave me due to a clash of a directory creation of the same name in the same folder by the above two files being executed. The error was given instantly unlike what I thought that the first file would run completely and then the Error should pop when the second file executes – Santanu Banerjee Sep 30 '22 at 07:16

0 Answers0