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

前端 未结 6 927
梦毁少年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:28

    One more technique, which doesn't import the sys module, and arguably - depends on your taste - simpler:

    current_module = __import__(__name__)
    

    Be aware there is no import. Python imports each module only once.

提交回复
热议问题