[PyKDE] QtCore.Qt and QtGui.Qt

Giovanni Bajo rasky at develer.com
Thu Mar 2 13:20:49 GMT 2006


Phil Thompson <phil at riverbankcomputing.co.uk> wrote:

>> ---------------------------
>> from PyQt4.QtCore import *
>> from PyQt4.QtGui import *
>>
>> dir(Qt)
>> ---------------------------
>>
>> won't show the full Qt namespace, thus making PyQt4 unusable without the
>> annoying QtCore/QtGui prefix in front of everything?
>
> Yes - I hadn't considered that - mainly because I don't adopt such a poor
> programming practice ;) Seriously, I don't have much sympathy for people
> using a feature that makes it easy to shoot yourself in the foot,

So you're one of those programmers who writes a Python module which uses Qt,
and defines a class called QWidget or qSIGNAL in it, which has nothing to do
with Qt? Because really, that's the only reason why you should suffer from
writing **and reading** all those boring and obfuscating QtCore and QtGui
prefixes everywhere. I don't need to read QtGui to know what a QComboBox is,
while I strongly need "re" to know what "compile" means.

The star-import is the equivalent of "using namespace" in C++. It's bad
practice to write "using namespace" in header files (for which there is
simply no equivalent in Python), but it's very common and actually *smart*
to write "using namespace" in source files, especially source files which
are tightly connected with the library wrapped in the namespace. It'd be a
major annoyance if C++ removed "using namespace", and in fact they are not
going to remove it.

But really, I'm not in a one-man war trying to change people's mind. People
are obviously free to use "UK.RiverbankComputingLtd.PyQt4.QtGui.QWidget" if
they find it useful, as long as PyQt official supports the star-import
alternative syntax.

> and which
> is slated for removal in a future version of Python.

It must be a *very* future version of Python, since its removal is not even
mentioned in PEP 3000.

> That said I can see lots of bug reports from lazy programmers, and I
> definitely want to avoid that.

Thanks, it's appreciated.
-- 
Giovanni Bajo




More information about the PyQt mailing list