Reputation: 1451
I have been looking into __init__.py
files, and see the recommendation is to handle the imports for the package there, and/or some initialization.
Then there is a package like Python Collections. That __init__.py
contains the implementations for different Collection objects.
Why would you place implementations in the __init__.py
instead of dedicated .py
files within the package? Is this a good idea? Is it a design pattern?
Upvotes: 3
Views: 119
Reputation: 522626
In this particular case, there's no need to have a directory with an __init__.py
file at all, since the only other file in that module is abc.py
, which defines nothing itself. So if it weren't for abc.py
, the entire thing should just be collections.py
instead of collections/__init__.py
. So why is it what it is? Purely for backwards compatibility reasons. They did not want to break from collections.abc import ...
, but wanted to move stuff around internally.
Upvotes: 2