简体   繁体   中英

execute python script from another file (after reaching end of file)

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 ?

您可以使用Subprocess模块“像用户一样”调用脚本。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM