I want to give command line arguments to a file and then executive that python file from within my master python file. How should I go about this?

I don't really care about the standard output. The file that I want to executive from with my file just outputs all its things to another output file. Therefore, all I want to find out is how to executive a python file (with command line arguments given) from within another python file?


7 Years
Discussion Span
Last Post by Tech B

try running files using terminal/cmd commands:

import os
os.system("file.py arg1 arg2 arg3")

also, if you wanted to run a python file without command line arguments, (don't quote me on this but im pretty sure you can't use CMAs this way) try this:

#import the file
import myfile

# run a function from myfile

# or if you dont want to put 'myfile' in front of all your variables/functions simply import all of the code using the asterisk symbol *:
from myfile import *

# now we dont have to type myfile.function()

hope that helps :)


you could also use something like exec()
it would be very inpractical though. os.sys() or os.popen() would be your best option.

to use exec() though could look something like:

f = open('name.py','r')
fr = f.readlines()
for i in fr:

but that would be too much and too complicated.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.