liveBook · Manning

__all__

As explained in Python Workout: 50 ten-minute exercises

__all__ is a module-level sequence that specifies which names are exported by a wildcard import from that module.

__all__ is a module-level sequence that controls which names a wildcard import exposes. It lets a module distinguish its public names from other definitions. section 8.10

Select names exported by a wildcard import

Define a module named stuff with variables a, b, and c, plus functions foo and bar. Set __all__ so that: __all__ = ['a', 'c', 'bar'] Then from stuff import * imports a, c, and bar, while excluding b and foo. section 8.10

Use the exercise to practice:

  • Creating a module with variables and functions. section 8.10
  • Choosing an explicit export set for from stuff import *. section 8.10

How Python Workout: 50 ten-minute exercises covers it

How deep it goes
Defines the export-selection behavior and assigns a small construction exercise, without discussing import internals.
Examples
Uses a stuff module containing a, b, c, foo, and bar to select a, c, and bar.
What you can do after
Build it from scratch by defining __all__ for a module’s wildcard-import interface.
How it connects
Connects modules, packages, imports, and wildcard imports.

Also explained in

Compare how 3 books explain __all__ →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Workout: 50 ten-minute exercises. The section links point to the parts of the book it draws on.