Part 1 · Section 09

Modules, Packages and Namespaces

Every import statement you write sets off a small chain of events: Python checks a cache, searches for code, builds a module object, runs the code inside it, and finally binds a name for you. Once you understand that chain, many puzzling behaviors make sense: why a module’s code runs only once, why from x import y doesn’t save memory, why reloading is risky, and how a package can present a simple interface over dozens of files.

In this section you’ll write real modules and packages to the browser’s in-memory file system and import them. You’ll learn:

Lectures

  1. 01What is a Module✓
  2. 02How Python Imports Modules✓
  3. 03Imports and importlib✓
  4. 04Import Variants and Misconceptions✓
  5. 05Reloading Modules✓
  6. 06Using __main__✓
  7. 07What are Packages✓
  8. 08Structuring Package Imports✓
  9. 09Zipped Packages✓

Practice: quiz & exercises

12 quiz questions · 3 coding exercises

Go to practice →