python Sequential Execution of Multiple py Files

  • 2021-07-06 11:19:48
  • OfStack

If I want to execute the python program in the code directory, suppose that there are 4 files in this directory: 1. py, 2. py, 3. py, 4. py, but I want to execute 1. py, 2. py, 4. py, then I can create an python file in this directory with the following code:


import os
os.system("python ./1.py")
os.system("python ./2.py")
os.system("python ./4.py")

If you want to specify output to a file, here I specify output to log. txt, log. txt is also in code directory, in the same directory as your code


import os
os.system("python ./1.py 1>>log.txt")
os.system("python ./2.py 1>>log.txt")
os.system("python ./4.py 1>>log.txt")

Related articles: