__init__.py in packages

Greg Ewing greg at cosc.canterbury.ac.nz
Wed Jun 8 23:11:34 EDT 2005


Gary Wilson Jr wrote:
> I would really like to see an example or situation that makes good
> use of the __init__.py file.

I've attached a non-trivial example, from my
PyGUI package. It uses some trickery to switch
in one of a number of subdirectories of platform
specific code, and then imports a bunch of names
from submodules into the top-level package, so
the user can pretend he's just using a single
top-level module, e.g.

  from GUI import Window

even though Window is actually defined in some
submodule.

This is a rather extreme example, though -- most
__init__.py files are much simpler!

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: __init__.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20050609/44305586/attachment.ksh>


More information about the Python-list mailing list