QamoosTech
Programming FundamentalsModules and librariesIntermediatePython

Wildcard Import

PronunciationWIL-kard IM-port

Definition

An import that brings every public name from a module into the current file, written as from module import *. It is quick to type, but it hides where each name comes from.

Where you hear it

In quick scripts, older code, and linter warnings.

Examples

  • from math import * brings sqrt, pi and every other public name into the file.
  • Import only the names you use: from math import sqrt, pi.
  • Linters warn about it, because a later import can silently replace an earlier name.

Common mistake

Using it in shared code. Two modules may export the same name, and the one imported last wins without any error.

Don't confuse with

A normal import such as import math keeps names under the module name, so math.sqrt shows where sqrt comes from. A wildcard import removes that prefix.

Say it at work

  • In a meeting or chatCan we swap the star import for explicit names so the linter stays quiet?
  • In an email or ticketStar imports make review hard: which module does this sqrt come from?