When does code in __init__.py get run?

后端 未结 1 1409
攒了一身酷
攒了一身酷 2021-02-01 02:01

I have read the documentation and there is something I\'m still not sure about. Does all the initialisation code for the whole module in __init__.py get run if I do

相关标签:
1条回答
  • 2021-02-01 02:24

    The code in __init__.py is run whenever you import anything from the package. That includes importing other modules in that package.

    The style of import (import packagename or from packagename import some_name) doesn't matter here.

    Like all modules, the code is run just once, and entered into sys.modules under the package name.

    0 讨论(0)
提交回复
热议问题