Call a python main from another python script
Question: I have been giving some huge command line tool from a colleague. The main
reads a bunch of arguments, parses those using the elegant `import
OptionParser` later on and does the job.

    
    
    if __name__ == '__main__':
        main(sys.argv)
    

I can either dig into the code and copy paste loads of code, or find a way to
use a "command line" call from my python script. I guess the second option is
preferrable as it prevents me from randomly extracting code. Would you agree ?


Answer: You don't need to do cut and paste or launch a new Python interpreter. You
should be able to [`import` the other
script](http://docs.python.org/reference/simple_stmts.html#import).

For example, if your colleague's script is called `somescript.py` you could
do:

    
    
    import somescript
    args = ['one','two']
    somescript.main(args)
    

