Skip to Content
Learning Python, 3rd Edition
book

Learning Python, 3rd Edition

by Mark Lutz
October 2007
Beginner
752 pages
19h 44m
English
O'Reilly Media, Inc.
Content preview from Learning Python, 3rd Edition

Chapter 18. 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. In concrete terms, modules usually correspond to Python program files (or extensions coded in external languages such as C, Java, or C#). Each file is a module, and modules import other modules to use the names they define. Modules are processed with two statements, and one important built-in function:

import

Lets a client (importer) fetch a module as a whole

from

Allows clients to fetch particular names from a module

reload

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. Part V begins by expanding on core module concepts, then moves on to explore more advanced module usage. This first chapter offers a general look at the role of modules in overall program structure. In the next and following chapters, 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 _ _name_ _ and _ _all_ _ attributes, package imports, and so on. Because modules and classes are really just glorified namespaces, we’ll formalize namespace concepts here as well.

Why Use Modules?

In short, modules provide an easy way to organize components into a system by serving as self-contained packages of variables known as namespaces. All the names defined ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Python, 6th Edition

Learning Python, 6th Edition

Mark Lutz
Learning Python, 2nd Edition

Learning Python, 2nd Edition

Mark Lutz, David Ascher

Publisher Resources

ISBN: 9780596513986Purchase bookSupplemental ContentErrata Page