A foobar package
Inside the __init__.py
from . import foo from . import bar
Even if bar not a package or subpackage, it is still imported as a module (lolwut). I checked the import type by doing print(type(bar)) inside __init__.py and typing <class 'module'> ... what it is. What's going on here? This is a module object, so I did print(dir(bar)) , and the result was ['__doc__', '__loader__', '__name__', '__package__', '__path__', '__spec__'] . Now, even more confusing to me, this is the __path__ variable. Isn't that just a batch thing?
Is this what is called a name pack? I think this is not the case, however, I tried one more thing inside this __init__.py file - added the line import bar.bar . It ended with ImportError . So, to summarize my question, why is this module useful? Why did Python import this in the first place?
There is an amazing tutorial on this subject by David Bezley . I watched all this a while ago, but I think I should watch it again to remember everything.
source share