Chapter 22. Modules: The Big Picture
This chapter begins our in-depth look at the Python moduleâthe highest-level program organization unit, which packages program code and data for reuse, and provides self-contained namespaces that minimize variable name clashes across your programs. In concrete terms, modules typically correspond to Python program files. Each file is a module, and modules import other modules to use the names they define. Modules might also correspond to extensions coded in external languages such as C, Java, or C#, and even to directories in package imports. Modules are processed with two statements and one important function:
Lets a client (importer) fetch a module as a whole
Allows clients to fetch particular names from a module
Provides a way to reload a moduleâs code without stopping Python
ChapterÂ 3 introduced module fundamentals, and weâve been using them ever since. The goal here is to expand on the core module concepts youâre already familiar with, and move on to explore more advanced module usage. This first chapter reviews module basics, and offers a general look at the role of modules in overall program structure. In the chapters that follow, weâll dig into the coding details behind the theory.
Along the way, weâll flesh out module details omitted so farâyouâll
learn about reloads, the
__all__ attributes, package imports, relative import syntax, 3.3 namespace packages, and so on. Because ...
Get Learning Python, 5th Edition 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.