[Python-Dev] New Import Hooks PEP, a first draft (and req. for
PEP #)
James C. Ahlstrom
jim@interet.com
Fri, 20 Dec 2002 15:41:29 -0500
Just van Rossum wrote:
> One more thought: finding modules and finding data files is not the same
> thing. Modules can be anywhere and must be accessible to anyone, but
> data files belong to specific modules. Searching the entire sys.path for
> a data file seems way too broad; there's got to be some information
> available as to where the data is. Eg. I doubt it's a *feature* that
> pdb.doc may also be found in site-packages.
I don't think that is a problem for packages, because
imp.find_module() does not accept dotted names now. To import
P.M you must currently import P, and then use P.__path__ as the path
in a call to imp.find_module().
Presumably the package author knows her package path, and
can use that in imp.find_module(). We aren't looking for
data files in Python std lib, right?
Hmmm. You have a point if the data is specific to a module and
not to a package. It seems we are forced to use __file__, the
only way to know the module's source. The __file__ can be
/usr/lib/python22/lib/os.pyc
/usr/lib/python/python22.zip/os.pyc
so if we strip off "os.pyc" the rest can be used as the path.
Hmmm. And if __file__ is None???
JimA