0

I have a text file inside which I have paths to a few python files and the arguments that I would specify when I run them in a command prompt.

I am looking for a python script that opens up the text file and runs the python programs specified in the text file along with the provided arguments.

The text file will look something like `C:\hello.py world

C:\square.py 5`

Kumaran Senapathy
  • 1,233
  • 4
  • 18
  • 30

2 Answers2

2

i think you should refer to below :

Calling an external command in Python

  1. Step One

read all lines in your command file get a list of python script file name and arguments like: " C:\hello.py and argument: word "

  1. Step Two

call them in below code style

from subprocess import call
call(["python C:\hello.py", "word"])
......
Community
  • 1
  • 1
Shawn Zhang
  • 1,680
  • 1
  • 12
  • 21
1

I don't think this post deserves down voting. But from now on I would suggest to OP to look for a solution yourself, and then if you can't find the answer post on stack overflow!

from subprocess import call

with open("somefile.txt", 'r') as f:
    some_files_to_run = [line.split('\n')[0] for line in f.readlines()]
    for file_to_run in some_files_to_run:
        call(["python", file_to_run])
Greg
  • 5,422
  • 1
  • 27
  • 32