How to get a reference to a module inside the module itself?

前端 未结 6 931
梦毁少年i
梦毁少年i 2020-12-07 11:55

How can I get a reference to a module from within that module? Also, how can I get a reference to the package containing that module?

6条回答
  •  抹茶落季
    2020-12-07 12:34

    You can get the name of the current module using __name__

    The module reference can be found in the sys.modules dictionary.

    See the Python documentation

提交回复
热议问题