Confused about namespaces

KvS keesvanschaik at
Sat Nov 19 02:05:37 CET 2005

> There's no reason not to just "import wx" if you want that.

Yes, that's clear. But if you would make some huge application that has
a large number of nested modules, each importing the former one, then
avoiding the use of "from ... import *" would mean that you have to use
long references like foo1.foo2.... to get to the lowest modules plus
that you'd have to check each module for imports outside this tree.

If you would use "from ... import *" (except at top level) you have to
be aware of overriding, but you can also use this to your advantage and
any foo1.attr reference would just work right, without further ado...
Or would in such a case a class hierarchy be the thing to use?

> No. It creates the foos within each module, but which foo you have
> access to in the importing module is determined by the order of
> import.

Am I understanding correctly that if you have a module foo importing wx
and a module main importing both foo and wx there are actually two
instances of wx created, one referenced to by (at top level) foo.wx.*
and one wx.*? If this is indeed the case it isn't too good for the
performance doing this importing of wx multiple times right?

- Kees

More information about the Python-list mailing list