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`

2 Answers 2

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"])
......
Sign up to request clarification or add additional context in comments.

Comments

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])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.