BoshWash
BoshWash

Reputation: 5440

Preferred way to import multiple modules from package

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

Answers (1)

wolfrevo
wolfrevo

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

Related Questions