*** GMX Spamverdacht *** Re: [PyQt] ImportError: No module named QtOpenGL

Mark Summerfield mark at qtrac.eu
Mon Apr 30 08:11:31 BST 2007


On Sun 29-Apr-07, Giovanni Bajo wrote:
> On 29/04/2007 6.25, Andreas Pakulat wrote:
> > Right, the motivation for the Qt.py package is simply convenience for
> > porting PyQt3 code. Which doesn't mean you should use it in new PyQt4
> > programs. Using something like this creates enough convience while
> > preserving a clean global namespace:
> >
> > from PyQt4 import QtCore,QtGui
> > from PyQt4.QtGui import QWidget, QPushButton <other classes you use very
> > often>
>
> I strongly disagree.
>
> Your suggestion creates gigantic import lines for absolutely no gain. It
> also encourages inconsistency in the source code base (where some classes
> have a QtNamespace prefix, and others don't) which is even WORSE and more
> confusing than the problem you're trying to solve (which is actually a
> non-problem, as I'm going to try to explain).
>
> The clean namespace is preserved by the implicit namespace that Trolltech
> uses (the 'Q' prefix in front of everything). If you call "QSomething" a
> class not realated to Qt in your Qt program, you should be shot in a front
> anyway by your reviewer.
>
> Which means that there is absolutely no need to clutter all your source
> code base with all those "QtCore." "QtGui." in front of everything. I have
> *never* been confused while reading a PyQt3 source code (that used the
> star-import); I have never found myself thinking "oh damn, this QSomething
> here! I thought it was Qt-realted but it is actually something else! They
> could have used an explicit "qt." namespace instead!".
>
> Being blind about this and thinking that "star-imports are bad no matter
> what" is just shooting oneself in the foot. The "star-import is bad"
> coding-standard rule shouldn't be taken literally (like any other
> coding-standard rule); if you understand what it really *means*, you also
> understand that it's not needed for PyQt.
>
> As Phil said, it's a matter of taste in the end. But surely, I know I'm
> using "from PyQt4.Qt import *" in all my new programs, and I know other
> people who do that as well.

Personally, I prefer:

    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    # etc

which still allows me to use QWidget etc unqualified, but at least
reminds me which of the 10 libraries I'm using.
    
But I agree with the general point that using "import *" is reasonable
when you have a large library like PyQt4---providing that library has
sensible export behaviour. For example, I _assume_ that the PyQt4
libraries will only export things with names matching /Q[A-Z]\w+/ and
would expect anything that didn't have such a name either not to be
exported or to have a special prefix such as "qt" to avoid unpleasant
surprises.



-- 
Mark Summerfield, Qtrac Ltd., www.qtrac.eu



More information about the PyQt mailing list