Reputation: 5440
What is the best way to import when you need several modules from a package?
from PySide.QtGui import QGraphicsView, QAction, QKeySequence, QMenu, QCursor, QKeyEvent
view = QGraphicsView()
...
or
import PySide.QtGui
view = QtGui.QGraphicsView()
...
or even
import PySide
view = PySide.QtGui.QGraphicsView()
...
I understand that in most cases the second way has the best tradeoff between ambiguity and length in the code. But are there any other considerations like performance when importing larger packages?
Upvotes: 1
Views: 4220
Reputation: 7293
I quote from the documentation:
"there is nothing wrong with using from Package import specific_submodule
! In fact, this is the recommended notation unless the importing module needs to use submodules with the same name from different packages."
Upvotes: 3