Chapter 25. Advanced Module Topics
This chapter concludes this part of the book with a collection of more
advanced module-related topics—data hiding, the
__future__ module, the
sys.path changes, listing tools, importing modules
by name string, transitive reloads, and so on—along with the standard set of
gotchas and exercises related to what we’ve covered in this part of the
Along the way, we’ll build some larger and more useful tools than we have so far that combine functions and modules. Like functions, modules are more effective when their interfaces are well defined, so this chapter also briefly reviews module design concepts, some of which we have explored in prior chapters.
Despite the word “advanced” used in this chapter’s title for symmetry,
this is mostly a grab-bag assortment of additional module topics. Because
some of the topics discussed here are widely used—especially the
__name__ trick—be sure to browse here before
moving on to classes in the next part of the book.
Module Design Concepts
Like functions, modules present design tradeoffs: you have to think about which functions go in which modules, module communication mechanisms, and so on. All of this will become clearer when you start writing bigger Python systems, but here are a few general ideas to keep in mind: