Package Organization (was Re: [Zope3-dev] Voting on Schema design)
Barry A. Warsaw
barry@zope.com
Mon, 15 Jul 2002 14:03:22 -0400
>>>>> "GvR" == Guido van Rossum <guido@python.org> writes:
GvR> In this case, the global variable __path__ in package Zope.
GvR> There could be code in its __init__.py that walks over
GvR> sys.path and looks for other directories named Zope and adds
GvR> them all to __path__.
GvR> (This is a little-known detail of the package interface I
GvR> guess. There's some info about it in
GvR> http://www.python.org/doc/essays/packages.html.)
Interesting. So Zope/__init__.py should contain something like:
-------------------- snip snip --------------------
import os
import sys
for dir in sys.path:
fullpath = os.path.join(dir, 'Zope')
initfile = os.path.join(fullpath, '__init__.py')
if os.path.exists(initfile):
# Should the other package be searched first or later?
__path__.append(fullpath)
-------------------- snip snip --------------------
One problem is the inability to answer the question in the comment,
since either answer may be correct depending on the circumstances.
-Barry