newbie question: getting a module in a package
Carey Evans
c.evans at clear.net.nz
Tue Sep 28 04:56:16 EDT 1999
"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 :) .
It probably makes a little more sense when you consider how Python
uses it, or how you'd do it in your own __import__. Doing something
like
>>> from spam.eggs import ham
will call __import__ with something like:
tmp = __import__('spam.eggs', globals(), locals(), ['ham'])
and even if ham is not present in spam.eggs, spam.eggs will still be
imported and put in sys.modules['spam.eggs']. It will fail just after
that when it tries to do the equivalent of:
locals()['ham'] = getattr(tmp, 'ham')
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__.
--
Carey Evans http://home.clear.net.nz/pages/c.evans/
"This is where your sanity gives in..."
More information about the Python-list
mailing list