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
_versions = [
    ("Carbon", "Mac"),
    ("gtk", "Gtk"),
]

from os import environ as _env
_platdir = _env.get("PYGUI_IMPLEMENTATION")
if not _platdir:
    for _testmod, _platdir in _versions:
        try:
            __import__(_testmod)
            break
        except ImportError:
            continue
    else:
        raise ImportError("Unable to find an implementation of PyGUI for this 
installation")

print "PyGUI: Using implementation:", _platdir

from os.path import join as _join
_here = __path__[0]
__path__.append(_join(_here, _platdir))
__path__.append(_join(_here, "Generic"))

from Version import version

from Actions import Action
from AlertFunctions import alert, alert2, alert3, \
    stop_alert, note_alert, confirm, ask, confirm_or_cancel, ask_or_cancel
from Applications import Application, application
from Buttons import Button
from CheckBoxes import CheckBox
from Colors import Color, rgb
from Components import Component
from Dialogs import Dialog
from Documents import Document
from Events import Event
from Exceptions import Cancel
from FileDialogs import request_old_file, request_new_file
from Files import FileRef, DirRef
from Fonts import Font
from Containers import Frame
from Images import Image
from Labels import Label
from Menus import Menu
from MessageHandlers import MessageHandler
from ModalDialogs import ModalDialog
from Models import Model
from Pixmaps import Pixmap
from Properties import Properties, overridable_property
from RadioButtons import RadioButton
from RadioGroups import RadioGroup
from ScrollBars import ScrollBar
from ScrollFrames import ScrollFrame
import StdColors
import StdFonts
from Tasks import Task
from TextFields import TextField
##from TextModels import TextModel
##from TextViews import TextView
from Views import View
from Windows import Window
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to