Chapter 3. Using Modules and Packages

To be able to use modules and packages within your Python programs, you need to understand how they work. In this chapter, we will examine the nuts and bolts of how modules and packages are defined and used in Python. In particular, we will:

  • Review how Python modules and packages are defined
  • See how packages can be created inside other packages
  • Discover how modules and packages can be initialized
  • Learn more about the import process
  • Explore the notion of relative imports
  • Learn how to control what gets imported
  • Find out how to deal with circular dependencies
  • See how a module can be run directly from the command line, and why this can be useful

Modules and packages

By now, you should be fairly comfortable with organizing ...

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.