using __init__.py

后端 未结 2 818
栀梦
栀梦 2020-12-04 11:20

I am having difficulty understanding the usage scenarios or design goals of python\'s __init__.py files in my projects.

Assume that I have \'model\' dir

2条回答
  •  执念已碎
    2020-12-04 11:38

    The contents of __init__.py are imported when you import a module within the package.

    You're overlooking a third scenario, which is to put the common parts in a separate module and then have the other modules import that, leaving __init__.py for things that will be used outside the package. This is the practice I usually follow.

提交回复
热议问题