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

Giovanni Bajo rasky at develer.com
Sun Apr 29 11:36:44 BST 2007


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.
-- 
Giovanni Bajo



More information about the PyQt mailing list