Explicit or general importing of namespaces?
peter at engcorp.com
Fri Mar 4 04:48:58 CET 2005
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.
More information about the Python-list