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 ?

Mahi
  • 3
  • 4
  • Possible duplicate of [Using python to run another program?](http://stackoverflow.com/questions/6945466/using-python-to-run-another-program) – TessellatingHeckler Jan 23 '16 at 03:00
  • You could execute `main.py` as a child process, is that what you mean? – tdelaney Jan 23 '16 at 03: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__`? – shmee Jan 23 '16 at 03:07

1 Answers1

0

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

Wakaru44
  • 423
  • 4
  • 14