Ever since PEP 420 has been implemented, the web offers plethora of advice along the lines: “Since python 3.3 you no longer need the
__init__.py to create a package…”, with or without referencing namespace packages and PEP 420.
The problematic scenario is as follows: someone creates a package in site-packages without the said
__init__.py file. They test it using a direct import and it works just as the “web” said. Then later someone else tries to import the same module programmatically using pkgutil.iter_modules() and the code no longer works, because iter_modules() does actually require the
I have been asked to explain this, and the truth is I can’t. I trivialize the answer to: RTFM, the Python.org doc literally states “The
__init__.py files are required to make Python treat directories containing the file as packages.”. Ignore the stack exchange stuff, it is plain wrong, the
__init__.py file is needed and that is that.
My answer may be a copout, but I don’t know what else to say. Am I missing something, or did the namespace package concept introduce this contradiction?