Chapter 11. Namespaces, Scopes, and Modules

In this chapter, we will cover Python modules. Modules are files containing functions and class definitions. The concept of a namespace and the scope of variables across functions and modules is also explained in this chapter.

Namespace

Names of Python objects, such as names of variables, classes, functions, and modules, are collected in namespaces. Modules and classes have their own named namespaces with the same name as these objects. These namespaces are created when a module is imported or a class is instantiated. The lifetime of a namespace of a module is as long as the current Python session. The lifetime of a namespace of a class instance is until the instance is deleted.

Functions create a local ...

Get Scientific Computing with Python 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.