Vladimir Gritsenko writes:
The basic idea behind using import foo instead of from foo
import * is namespace cluttering, which can lead to importing
functions, procedures, classes, globals, etc., which have the
same name, thus leading to unpredictable behaviour and broken
code, not to mention your own custom functions, classes, etc.
Also, it looks ugly, and can clutter up the semantic
namespaces inside of people's heads (when reading your code).
Exactly. To see this point, do the following:
import wx
len(dir(wx))
3143
dir(wx)
(pages and pages of identifiers flow by)
So, 3,143 names exist in the wx namespace. Now, that is a lot of
names, but at least I know that none of these names will ever
conflict with any of my names.
With the 'from wxPython import *' form, those 3,143 names go
into the global namespace, potentially conflicting with names
from other modules or from your own code. And even if they
don't conflict, it is certainly a bear to find your own needles
from inside that haystack.
From "The Zen of Python" by Tim Peters (see
http://www.python.org/doc/Humor.html#zen), the very last item
in the list is:
"Namespaces are one honking great idea -- let's do more of
those!"
···
--
Paul McNett
Independent Software Consultant
http://www.paulmcnett.com