newbie question: getting a module in a package
Guido van Rossum
guido at cnri.reston.va.us
Tue Sep 28 07:46:02 EDT 1999
(Apparently on why __import__ takes a 4th argument which is a list but
for which only empty/non-empty is checked):
Carey Evans <c.evans at clear.net.nz> writes:
> "Mike Fletcher" <mcfletch at vrtelecom.com> writes:
>
> > It's rather awkward looking, but it seems to work here... the operation
> > seems a little arbitrary to me (why bother to check for non-empty list if
> > you're not using the values for anything?) It's documented, I just think
> > it's weird :) .
>
[...]
> Umm, maybe it's still wierd. Still, for good form I'd probably pass
> the name of at least one of the things I was looking for in spam.eggs
> to __import__.
It's weird (not wierd! you young-un's don't know how to spell any more :-)
for what's affectionately known as hysterical raisins -- __import__
had to be tightly compatible with the built-in import support that
existed in Python 1.1.
But the list of names *is* used by package imports -- if you write
from some_package import submodule1, submodule2, ...
then __import__ is called as
__import__("some_package", globals(), locals(),
["submodule1", "submodule2", ...])
and the package import mechanism must ensure that the files
submodule1.py, submodule2.py, ... are actually loaded.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-list
mailing list