Explicit or general importing of namespaces?

Harlin Seritt hseritt at pythonian.com
Sat Mar 5 01:18:02 CET 2005

I think the bottom line on this is using your own sense of risk/reward with
each given module imported. Some modules (Tkinter comes to mind) it makes
sense to pollute while others it doesn't.


"Peter Hansen" <peter at engcorp.com> wrote in message
news:4K2dnfB_BcgwR7rfRVn-ig at powergate.ca...
> Peter Mayne wrote:
> > Peter Hansen wrote:
> >> and it's still a bad idea in almost all cases anyway
> >
> > Since I've been playing with PyQt lately...
> >
> > Is qt not one of the "almost all" cases? From the limited number of
> > examples I've seen, it seems to be common to do
> >
> > from qt import *
> This sort of thing seems common amongst large frameworks such
> as PyQt or wxPython.  This is unfortunate, IMHO, though it isn't
> really a serious concern for most users.
> I'm grateful that the most recent versions of wxPython have
> abandoned that approach in favour of a nice clean "import wx",
> and as far as I can tell the code does not suffer as a result,
> and gains substantially in clarity.  Maybe the "qt" module
> defines far fewer names than the "wx" module does, but I for
> one am glad not to have to worry that I won't accidentally
> conflict with the hundreds that are there (in wx), nor to
> worry that my code lacks in readability.
> > Since most of the imported names start with "Q", are called QLabel,
> > QSlider, etc, and are generally recognisable in context, this would seem
> > to be a reasonable case of namespace pollution.
> >
> > I'm certainly not arguing with the general premise, just wondering if qt
> > is one of the sensible exceptions.
> If not sensible, at least fairly widely accepted, not a serious
> impediment to effective use, and definitely not without precedent.
> -Peter

More information about the Python-list mailing list