In some codes, I have seen "from qiskit import QuantumCircuit, aer, execute". Some say "From qiskit import *".

This is python related, I understand, but with respect to Quantum World,

  1. In first case, I am explicitly importing the objects(correct me if this is not the wright word) . In case 2, I am importing everything. Is there an advantage of doing case 1? In case 2, cos of generic nature, should not it be more useful in coding?

  2. what is the full spectrum of *. How to check that for qiskit?


1 Answer 1


Doing from qiskit import * is a usually discouraged. From https://docs.python.org/3/tutorial/modules.html#importing-from-a-package

Although certain modules are designed to export only names that follow certain patterns when you use import *, it is still considered bad practice in production code.

While Qiskit is setting that pattern here, doing from qiskit import * might result in unexpected/cryptic error messages because the namespace pollution. If you use any form of interactive Python, such as ipython or Jupyter notebooks, you can have all the possible objects to import by pressing Tab key: from qiskit import <tab>.


Not the answer you're looking for? Browse other questions tagged or ask your own question.