QamoosTech
Programming FundamentalsModules and librariesBeginner

Namespace

PronunciationNAYM-spays

Definition

A container that groups names so that the same name can exist in different places without a clash, such as math.sqrt and numpy.sqrt, or a module that holds its own functions.

Where you hear it

In Python imports, XML and C# code, and in naming discussions about large projects.

Examples

  • Use the namespace math.sqrt so it does not clash with another sqrt.
  • Keep the logging helpers in their own namespace.
  • The billing code and the shipping code both define a create function, each in its own namespace.

Common mistake

Using wildcard imports, such as from module import *, which pull many names into your namespace and cause clashes.

Don't confuse with

A namespace groups names in code. A module is one file that defines some of them, and a package is a folder of modules. A Linux namespace is a different idea: it isolates system resources for a process, as used by containers.