从另一个文件中运行Python脚本(在文件结束后执行)
- 论坛
- 从另一个文件中运行Python脚本(在文件结束后执行)
12 浏览
从另一个文件中运行Python脚本(在文件结束后执行)
我想从另一个文件(比如test.py)中执行脚本(比如main.py),不想调用main的任何函数,而是想从if __name__==\"__main__\":
开始执行文件
示例:
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)
像这样直接调用main是可能的吗?
admin 更改状态以发布 2023年5月20日