Package importing question
Nick Patavalis
npat at efault.net
Tue Mar 9 21:47:15 EST 2004
In article <c2l8n5$sqa$1 at news.eusc.inter.net>, Daniel Dittmar wrote:
>
> Because all sub modules of package p0 get inserted into the module
> object for p0. This is so that a later import of p0.m1 won't
> import/execute it again. And you did import p0.m1 through the 'import
> m1' in m0.
>
Yes, but according to this, why doesn't 'sys' show up when I do:
dir()
After all, I did imported sys through import p0.m0 ????
What if I did something like this:
>From the main I do:
import p0
>From within p0.m0 I do
import p1.m1
Latter from main I do
import p1
will 'm1' show-up in dir(p1)?
What I tend to understand is this: When I import a module, some kind
of dictionary is created for it and a binding to this dictionary is
created in the dictionary of the importing module. So after an import
p0.m0, the situation is like this:
+-----+
| |
| V
main | p0
+-+ | +-+
| | | | |
|*|----+ | |
| | |*|--+
| | +-+ |
+-+ |
V
m0
+-+
| |
| |
|*|--+
+-+ |
|
V
f0
After an import m1, from within p0.m0, I would expect things to be
like this:
+-----+
| |
| V
main | p0
+-+ | +-+
| | | | |
|*|----+ | |
| | |*|--+
| | +-+ |
+-+ |
V
m0
+-+
|*|-------+
| | |
|*|--+ V
+-+ | m1
| +-+
V | |
f0 | |
|*|----> f0
+-+
But what you say, and what seems to be the case in reality, is:
+-----+
| |
| V
main | p0
+-+ | +-+
| | | |*|---------------+
|*|----+ | | |
| | |*|--+ |
| | +-+ | |
+-+ | |
V |
m0 |
+-+ |
|*|-------+ |
| | | |
|*|--+ V |
+-+ | m1<-+
| +-+
V | |
f0 | |
|*|----> f0
+-+
So the first obvious question is how was m0 able to find the p0
dictionary and the binding to m1? Am I getting something totally
wrong so far?
/npat
More information about the Python-list
mailing list