我有这个 python 脚本,它不会按照我想要的正确顺序运行。这是代码:
import VT as vt
import VT_Tests
import AUTO as auto
def main():
auto.run()
vt.run()
if __name__ == '__main__':
main()
我希望它首先运行AUTO
模块,但它只是先跳到另一个模块。
我有这个 python 脚本,它不会按照我想要的正确顺序运行。这是代码:
import VT as vt
import VT_Tests
import AUTO as auto
def main():
auto.run()
vt.run()
if __name__ == '__main__':
main()
我希望它首先运行AUTO
模块,但它只是先跳到另一个模块。
The body of the module is executed in the import
statement. Your problem is probably that you are VT_Tests is calling vt.run()
in its body - it shouldn't. You should test for __name__
just like you did here before calling anything you don't want to be called upon import.