Why is __init__.py required

David Niergarth jdnier at execpc.com
Mon Aug 2 00:58:33 EDT 1999


G. David Kuhlman <dkuhlman at netcom.com> wrote in message
news:7o2eeq$gs2 at dfw-ixnews6.ix.netcom.com...
> 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 just noticed earlier today that you can put code *in* an __init__.py file,
which makes that file seem a little more useful! For example, see the source
of mxTextTools ( http://starship.python.net/~lemburg/mxTextTools.html ) or
the XML package (and probably lots of other packages). It's a feature I've
never seen explained.

--David Niergarth







More information about the Python-list mailing list