1. Concept library
  2. Python Foundations
  3. Module 8: Modules and packages

Concept

Imports

import brings another module's names into yours. A module is just a file; a package is a folder of them. How you import decides what name you use and how readable the result is.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain the difference between import x, from x import y and import x as z
  2. Write a module of your own and import a function from it
  3. Explain how a package differs from a module

In practice

A few lines that show Imports doing its job.

Python
import math
from pathlib import Path
from collections import Counter as Tally

print(math.sqrt(16))
print(Path("data") / "input.csv")
print(Tally("banana").most_common(1))

The common mistake

Watch for

Naming your own file after a library, such as random.py, and then importing random. Python finds your file first and the import silently returns the wrong module.

What to know first

Your roadmap puts these before Imports, unless you already know them.

How it stays learned

Once a session shows you understand Imports, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Where it leads

Topics that build on Imports.

Next in the moduleVirtual environments →