Confused about namespaces
Alex Martelli
aleax at mail.comcast.net
Fri Nov 18 21:37:35 EST 2005
KvS <keesvanschaik at gmail.com> wrote:
> > 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
Not at all -- you may perfectly well "import a.b.c.d as e" and use e as
the reference throughout the importing module.
But the point is, modules should be MODULAR (duh) -- if I 'import x' I
should NOT rely on what x itself imports (and so on transitively), just
on what x ``exports'', so to speak, at its TOP level. The Law of
Demeter in its simplified form "if you have more than one dot in your
reference you're doing things wrong" applies. In fact, the many-dots
form of module naming is intended for nested PACKAGES, *NOT* for
"modules which import each other".
> that you'd have to check each module for imports outside this tree.
Why would you have to check any module for such "outside imports"? I
don't see the need for any checks.
If you just simply forget the very _existence_ of "from X import *",
your Python code can only grow better as a result. I earnestly hope it
disappears come Python 3.0 time...
Alex
More information about the Python-list
mailing list