User
User

Reputation: 24731

import PyQt4 does not include PyQt4.QtCore or QtGui

Why do neither of these statements import QtCore, QtGui, QtNetwork or any of the others? I've searched so long and can't find anyone to answer such a simple question. Or at least that's what I think it is.

import PyQt4
from PyQt4 import *

Instead I have to do:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtNetwork import *

Plus a bunch more. Any shortcuts to grab them all?

Edit: My solutions was to go through the libraries that I was using (for Py2exe) and just copy their imports. That worked. Still, but not as tedious.

Upvotes: 1

Views: 7054

Answers (2)

ekhumoro
ekhumoro

Reputation: 120608

If you want to import all PyQt4 classes into a single namespace, you can do:

from PyQt4 import Qt

Upvotes: 3

user764357
user764357

Reputation:

Don't use import *, namespaces exist for a good reason.

Import the modules you need, in the modules you need them in.

This code might require a few extra letters, but you'd only know QUrl was a Qt module by convention, not surety.

 from PyQt import QtCore
 u = QtCore.QUrl

The above code means when you are examining the second line you know for certain that it is a Qt object from a specific module and nothing else.

Upvotes: 3

Related Questions