Execute multiple python files using a single main

前端 未结 4 960
Happy的楠姐
Happy的楠姐 2021-01-06 12:55

I have multiple python files, each with different classes and methods in it. I want to execute all those files with a main function I have separately outside all of them.

4条回答
  •  自闭症患者
    2021-01-06 13:25

    use them as modules and import them into your script containing main.

    import one
    import two
    import three
    
    if __name__ == '__main__':
        one.foo()
        two.bar()
        three.baz()
    

提交回复
热议问题