Chapter 10. Modules and scoping rules

This chapter covers:

  • Defining a module
  • Writing a first module
  • Using the import statement
  • Modifying the module search path
  • Making names private in modules
  • Importing standard library and third-party modules
  • Understanding Python scoping rules and namespaces

Modules are used to organize larger Python projects. The Python standard library is split into modules to make it more manageable. You don’t need to organize your own code into modules, but if you’re writing any programs that are more than a few pages long, or any code that you want to reuse, you should probably do so.

10.1. What is a module?

A module is a file containing code. A module defines a group of Python functions or other objects, and the ...

Get The Quick Python Book now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.