Intuition The one core idea
A module is a .py file someone already wrote, and importing it is nothing more than making a name in your file point to the finished contents of that file . Everything else in this topic — the dot, from, as, *, sys.path — is just a different way of controlling which names appear in your file and where they point.
Before you can read a single import line, you need to be fluent in the small pieces it is built from: what a file is, what a name is, what the dot does, and what a namespace is. This page builds each of those from nothing, in the order they stack on top of each other.
.py file
A ==.py file== is an ordinary text file whose name ends in .py. Its contents are Python instructions. The .py ending is a label to humans and to Python that says "this text is meant to be run as Python."
Picture a folder on your computer. Inside it sit two text files, main.py and helper.py. Nothing magic — just text on disk.
Intuition Why the topic needs this
A module is a .py file. If you don't picture files sitting in a folder, phrases like "Python finds math.py" or "your file random.py shadows the real one" are meaningless. The whole topic is about how one file reaches into another file.
Definition Name (variable)
When you write x = 42, the = does not mean "equals" like in maths. It means "make the label x point at the value 42." The label on the left is a name ; the thing on the right is the value (the object).
Think of a name as a luggage tag tied by a string to a suitcase. The tag is x; the suitcase is 42. You can re-tie the same tag to a different suitcase later (x = 99).
Intuition Why the topic needs this
Every form of import ends by creating a name that points at something. import math ties the tag math to the whole finished module. from math import sqrt ties the tag sqrt to just one function inside it. Once you see imports as tag-tying , the four forms stop being magic spells and become "which tag, pointing at what."
= means both sides are the same, like 2 + 2 = 4"
Why it feels right: you've seen = in maths your whole life.
Why it's wrong here: in Python, x = 42 is an action — "point x at 42" — not a statement of fact . That's why x = x + 1 is legal (compute x + 1, then re-point the tag), which would be nonsense in maths.
The fix: read = as the arrow "←" in your head: x ← 42.
A namespace is a container that holds a set of names, each pointing at its own value. Two different namespaces can both hold a name pi pointing at different values, and they never fight, because they live in separate boxes.
Picture two separate drawers. Your drawer has a tag pi on a suitcase holding 3 (you were sloppy). The math drawer has a tag pi on a suitcase holding 3.14159…. Same tag word, different drawers — no collision.
Intuition Why the topic needs this
The parent note says a module gives you a "container of names so its pi doesn't clash with your pi." That container is a namespace. Understanding it explains why import math is safe (pi stays in the math drawer) but from math import pi is riskier (pi gets copied into your drawer, where it can overwrite yours). See Namespaces and Scope for how these drawers nest.
Definition The dot operator
The dot in math.sqrt means "go into the namespace on the left (math) and fetch the name on the right (sqrt)." It is the tool for reaching inside a box.
If math is a drawer, then math.sqrt is you saying "open the math drawer, take out the sqrt tool." The dot is the act of opening the drawer.
Intuition Why the topic needs this
Half the topic is "prefix or no prefix?" The dot is the prefix. import math → you keep the dot (reach into the drawer each time). from math import sqrt → the tag sqrt is now in your own drawer, so no dot needed. Every "why the math. prefix?" question in the parent is answered by this one picture.
Now that names, namespaces, and the dot exist, the keywords are just verbs acting on them.
Definition The four keywords
==import== — run the target file once, then create a tag in your drawer pointing at the finished module.
==from== — "starting from that module, reach in and copy out specific tags " (so they land directly in your drawer).
==as== — "and put a different tag word on it" (a nickname; the suitcase is unchanged).
==*== — "copy out every public tag" (the risky bulk grab).
Worked example Reading each form as tag-actions
import math # your drawer gains tag: math
from math import sqrt # your drawer gains tag: sqrt
import numpy as np # your drawer gains tag: np (points at numpy)
from math import sqrt as s # your drawer gains tag: s (points at math's sqrt)
Notice: every line ends by adding one or more tags to your drawer. That is the entire mechanism.
sys.path
==sys.path== is a list of folder names Python searches, top to bottom, to find the file you asked to import. First folder that contains a matching .py wins; the search stops there.
sys.modules
==sys.modules== is a dictionary of already-imported modules . Before running any file, Python peeks here. If the module is already listed, it skips the "run the file" step and reuses the finished object — this is why importing twice does not run the file twice.
Intuition Why the topic needs both
sys.path explains where Python looks (and why random.py in your folder shadows the real one — your folder is checked first). sys.modules explains run-once caching. Both live in the sys and os modules ; the dot you learned in step 4 is exactly how you'd read them (sys.path, sys.modules).
a namespace is a box of names
the dot reaches into a box
import from as star act on boxes
Modules topic import from import as
Read it bottom-up: files and names are the ground; namespaces group names; the dot reaches into a namespace; the keywords manipulate namespaces; sys.path tells Python which file to open. All of it feeds the Modules topic .
Namespaces and Scope — the "box of tags" picture, formalised.
sys and os modules — where sys.path and sys.modules live.
Python Functions — the most common thing a module hands you.
Packages and __init__.py — what happens when one drawer becomes a cabinet of drawers.
DRY Principle — the reason modules exist at all.
A .py file is — in plain words? An ordinary text file ending in .py whose contents are Python instructions Python can run.
x = 42 means, read as an action?"Point the tag/name x at the value 42" — it re-ties a label, it is not a maths equality.
A namespace is? A box/container holding names, each pointing at a value; separate namespaces can reuse the same name without clashing.
The dot in math.sqrt does what? Reaches into the namespace math and fetches the name sqrt from inside it.
After import math, which tags are in YOUR drawer? Just one: math. To get sqrt you must use the dot: math.sqrt.
After from math import sqrt, which tag is in YOUR drawer? sqrt itself, copied directly in — so no dot is needed.
What does as change — the suitcase or the tag? Only the tag word (the nickname); the underlying object is exactly the same.
sys.path is?An ordered list of folders Python searches to find the file to import; first match wins.
sys.modules is, and why it matters?A cache of already-imported modules; it makes a module's top-level code run only once.