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

前端 未结 5 1505
灰色年华
灰色年华 2020-12-01 14:05

my problem is that I want to execute a python file with an argument from inside another python file to get the returned values....

I don\'t know if I\'ve explained

5条回答
  •  执念已碎
    2020-12-01 14:55

    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

提交回复
热议问题