Q: Why is __init__.py required
Gordon McMillan
gmcm at hypernet.com
Sun Aug 1 23:26:27 EDT 1999
G. David Kuhlman writes:
> I have looked and looked for this. Whenever I put an empty
> __init__.py in a package, I ask myself why I have to do this. I
> read Guido's article on packages and it told me that I have to put
> an __init__.py in a directory in order for the directory to be
> recognized as a package. But it doesn't say why.
>
> I'm not asking for this behavior to be changed. I like it the way
> it is. I just want to know *why* it has to be that way. In what
> way would the Python interpreter get confused if it didn't have
> __init__.py to distinguish package directories from non-package
> directories?
import a.b becomes:
import a
if a is a package:
in this same directory, look for b
else
get this thing called b out of module a
> It bugs me when I don't know why. My parents used to have to
> explain things to me like why I couldn't jump off the roof of the
> house.
they-sure-blew-that-one-<wink>-ly y'rs
- Gordon
More information about the Python-list
mailing list