In Python, can I call the main() of an imported module?

后端 未结 6 2018
时光取名叫无心
时光取名叫无心 2020-11-29 17:36

In Python I have a module myModule.py where I define a few functions and a main(), which takes a few command line arguments.

I usu

6条回答
  •  独厮守ぢ
    2020-11-29 17:45

    Assuming you are trying to pass the command line arguments as well.

    import sys
    import myModule
    
    
    def main():
        # this will just pass all of the system arguments as is
        myModule.main(*sys.argv)
    
        # all the argv but the script name
        myModule.main(*sys.argv[1:])
    

提交回复
热议问题