当前位置: 首页 > 工具软件 > we-script > 使用案例 >

理解Python -m mod : run library module as a script

仲孙毅
2023-12-01
  • -m

    from python -h, -m mod : run library module as a script (terminates option list).

    Python modules are just script files that are located in a place where Python can find them.

    As with all scripts, you can just run them directly if you know where they are, e.g. python /path/to/module.py

  • __name__ in Python

    As we learn from What does if __name__ == “__main__”: do? ,a .py file can be executed in two ways:

    1. as main program
    2. imported by another
  • run library module as a script

    If you want run a module as main program, you should know the full path to the module ,like python /path/module.py, also can use the python -m module just get the same result.

    直接执行的是module.py脚本,通过-m参数是执行module实现执行module.py的效果。

 类似资料: