Summary

In this chapter, we looked at the details of how Python modules and packages work. We saw that modules are simply Python source files that get imported using an import statement, and that packages are directories of Python source files identified by a package initialization file named __init__.py. We learned that packages can be defined inside other packages to form a tree-like structure of nested packages. We looked at how modules and packages can be initialized, and how the import statement can be used in various ways to import modules and packages, and their contents, into your programs.

We then saw how relative imports can be used to import modules relative to your current position in the package hierarchy and how the __all__ variable ...

Get Modular Programming with Python 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.