2

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 ?

1
  • 1
    from another_script import main Commented Dec 9, 2011 at 10:09

1 Answer 1

8

You don't need to do cut and paste or launch a new Python interpreter. You should be able to import the other script.

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

import somescript
args = ['one','two']
somescript.main(args)
Sign up to request clarification or add additional context in comments.

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.