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' directory (refers as a package) which contains the following files
__init__.py
meta.py
solrmodel.py
mongomodel.py
samodel.py
I found two ways of using __init__.py
:
I have common a definition which needs to be used in
solrmodel.py
,mongomodel.py
,samodel.py
. Can I use__init__.py
as a base/common definition for all the *model.py classes? This means that I have to importmodel/__init__.py
.Or, the
__init__.py
shall have imported definitions of solrmodel.py, mongomodel.py, samodel.py in its own and it allows the easy import of classes or function like this:# file: __init__.py from mongomodel import * from solrmodel import * from samodel import *
(I am aware that
import *
is not recommended and I just used it as a convention)
I could not decide between above two scenarios. Are there more usage scenarios for __init__.py
and can you explain the usage?