0

I am trying to develop this program , that invokes the main function of another program and takes the program to be inkoved's name as user input , let us call this program 1 :

Program 1 # takes the program 2's name as user input

try:

    print "Please input the file you want to test"
    filename = raw_input().split(".")[0]
    module = __import__(filename)

except:

program 2 is like

def main():
    first()

def first():
    5/0

if __name__ == "__main__":
    main()

so basically I want to know how to invoke program 2's main function from program 1 .

thank you

3
  • Try importing the other file. Commented Dec 7, 2012 at 0:58
  • module = __import__(filename) does exactly that Commented Dec 7, 2012 at 1:02
  • I meant by using the import statement. In either case, you can treat it like a regular module; I don't see where the issue lies. Commented Dec 7, 2012 at 1:08

1 Answer 1

1

Just do module.main() - there's nothing special about a function called main

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.