Execute an installed Python package as a script?

后端 未结 3 1465
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 23:48

Is there a way to enable a package to be executed as a script? For example:

[~]# easy_install /path/to/foo.egg
...
[~]# python -m foo --name World
Hello Worl         


        
3条回答
  •  北海茫月
    2020-12-05 00:54

    as long as the package is on the python path, add at the end of the script.

    if __name__ == "__main__":
         call_script()
    
    $ python -m module_name  

    will run the module e.g

    python -m random
    

提交回复
热议问题