[PyQt] PyQt4.Qtcore defines 'hex'

Mark Summerfield mark at qtrac.eu
Wed Jan 7 12:28:39 GMT 2009


On 2009-01-07, Chris Withers wrote:
> Phil Thompson wrote:
> >>> This has been discussed thousands of times and it starts getting
> >>> annoying.
> >>
> >> Yes, it is annoying that all the example code continues to be in a form
> >> that confuses users trying to learn PyQt.
> >
> > *None* of the PyQt4 examples uses star imports.
>
> Hmmm, apologies then, must have been exclusively a problem with Mark
> Summerfield's tutorial stuff.

I have now switched to a new style for imports, for example:

from PyQt4.QtCore import (PYQT_VERSION_STR, QFile, QFileInfo, QSettings,
        QString, QT_VERSION_STR, QTimer, QVariant, Qt, SIGNAL)
from PyQt4.QtGui import (QAction, QActionGroup, QApplication,
        QDockWidget, QFileDialog, QFrame, QIcon, QImage, QImageReader,
        QImageWriter, QInputDialog, QKeySequence, QLabel, QListWidget,
        QMainWindow, QMessageBox, QPainter, QPixmap, QPrintDialog,
        QPrinter, QSpinBox)

This avoids importing confusing junk while still allowing you to write
nice things like:
    
    action = QAction("Action")

The disadvantage is that you keep having to extend the lists of imports
as you develop and maintain your code.

I don't want to change this for the book's examples because I want them
to exactly match the text---although actually, the only change is to the
imports, the use of the classes is unchanged. However I've done a
separate set of Python 2.6 versions of the examples and these use the new
import style.

> FWIW, I still think sticking a _ on the end of the name is silly...

Yes, but it has precedents in PyQt already, e.g. QApplication.exec_().

>
> (and in my previous mail when I said "David" I actually meant "Mark",
> happy new year ;-) )

Understandable since David is a much more regular poster than I am:-)

-- 
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
    C++, Python, Qt, PyQt - training and consultancy
        "Programming in Python 3" - ISBN 0137129297



More information about the PyQt mailing list