Q: Why is __init__.py required

Aahz Maruch aahz at netcom.com
Sun Aug 1 20:20:53 EDT 1999


In article <7o2eeq$gs2 at dfw-ixnews6.ix.netcom.com>,
G. David Kuhlman <dkuhlman at netcom.com> wrote:
>
>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.

Look at it this way: say you give Python the name of a directory.  How
does Python know that the directory really is a package, rather than
some random directory?  Like much else in Python (e.g. ":", "=="), this
straitjacket is designed to save you time by preventing stupid mistakes.
--
                      --- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het    <*>      http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6  (if you want to know, do some research)




More information about the Python-list mailing list