Entire Module Is Not Detected By __init__.py
I have a relatively small python program which is setup like this Root --Network --DTO Lots of py files which contain classes. Other py files in the project Both in
Solution 1:
For that, you need to import the submodules in your __init__.py
. It becomes more difficult to add an import for every submodule if you have many, as you do. In the case of many submodules (and in general), use __all__
.
Here's an example for Root/Network/DTO/__init__.py
:
__all__ = [
'sample_module',
...
]
formodule in __all__:
__import__('DTO.%s' % module)
Now you can do from Network.DTO import sample_module
. The same idea holds for your other modules, as well.
Post a Comment for "Entire Module Is Not Detected By __init__.py"