1

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?

1
  • The best for you is to check if its suit pep8 commandments. sudo apt-get install pep8 pep8 yourpythonscript.py Watch the output and edit, for sure it while yell for exceeding 80 characters. Commented Mar 3, 2014 at 19:22

1 Answer 1

3

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."

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.