How to know if python script was run using interpreter's -m option?

后端 未结 2 1026
陌清茗
陌清茗 2021-01-02 13:48

I couldn\'t find answer after having read all the following:

  • PEP 338 Executing modules as scripts
  • documentation of runpy standard modul
2条回答
  •  暖寄归人
    2021-01-02 14:09

    Another observation is that __package__ is set to None when executing the script directly and to the package name when using -m (using the empty string when the module isn't included in any package, so it's still different from None).

提交回复
热议问题