How to execute a python script file with an argument from inside another python script file

The best answer is don’t. Write your getCameras.py as

import stuff1
import stuff2 
import sys

def main(arg1, arg2):
    # do whatever and return 0 for success and an 
    # integer x, 1 <= x <= 256 for failure

if __name__=='__main__':
    sys.exit(main(sys.argv[1], sys.argv[2]))

From your other script, you can then do

import getCamera

getCamera.main(arg1, arg2)

or call any other functions in getCamera.py

Leave a Comment