0

I am trying to execute script (say, main.py) from another file (say, test.py), I don't want to call any function of main, instead i want to start executing the file from if __name__=="__main__":

Example:
test.py

def funA():
    ....
def funB():
    ....
#the last function of file
def funC():
    #here i want to start executing main.py without calling any function. 

main.py

def fun_x(arg1):
    #do something

if __name__ == "__main__":   #execution starts here
     arg1=10
     x(arg1)

Is it possible to call the main directly like this ?

3
  • Possible duplicate of Using python to run another program? Commented Jan 23, 2016 at 3:00
  • You could execute main.py as a child process, is that what you mean? Commented Jan 23, 2016 at 3:02
  • Why not omit the __name__ == "__main__", and import the main.py in funcC()? What's the point in having this check if main.py is not supposed to be __main__? Commented Jan 23, 2016 at 3:07

1 Answer 1

0

You can just call the script "like a user would do" with The subprocess module.

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.