How to Read Code You Did Not Write as a Beginner
A student in my Tuesday group handed me a 70 line Python file last month and asked why it kept printing the same name four times. She had written none of it.

A student in my Tuesday group handed me a 70 line Python file last month and asked why it kept printing the same name four times. She had written none of it. A friend had sent it to her as a starting point for a class register tool, and she had spent two evenings adding features to a program she could not describe. When I asked what the second loop did, she said it loops through the list. That was true and it was not an answer.
Almost everything we give beginners teaches writing. Exercises, courses, the first forty hours of any Python book: all of it points at producing code from a blank file. Then real work arrives and the first task is almost always reading. Somebody sends you a file, or you clone a repository, or you return to your own project after a month away and it may as well be a stranger's. I taught maths for eleven years before I taught Python and this is the closest parallel I know to reading a proof written by someone else. You cannot do it by starting at line one and moving down.
Reading is a different skill from writing
When you write code, you hold the intention first and the syntax second. You know you want to count something, so the loop and the counter variable fall out of that. Reading reverses the order. You have the syntax in front of you and you have to reconstruct an intention that lives in somebody else's head, often someone who was in a hurry.
That reversal is why beginners who can write a working word counter stall on a 70 line file. Nothing in the file is beyond them line by line. The difficulty is that there are forty decisions in it and they arrive in an order chosen for the machine rather than for a reader. A function defined at line 8 might not run until line 61, and the variable it depends on might get changed at line 34 by something that looks unrelated.
The other half of the problem is a feeling rather than a skill. Reading unfamiliar code is uncomfortable in a way that writing is not, because you are confronted with the gap between what you understand and what somebody else already knew. Around half the learners I sit with apologise during this exercise. There is nothing to apologise for, and knowing that the discomfort is standard makes people stay in the file longer.
The three passes I teach
I give everyone the same routine, and I ask them to resist reading line one until the third pass.
The first pass is shape. Scroll the whole file once without reading any logic and write down only the names: which functions exist, how long each one is, what gets imported, and where the file actually starts doing something. In a Python script that last point is usually a block at the bottom guarded by a check on the module name, or just a few bare calls. Five minutes on this tells you more than twenty minutes of line by line reading, because you now have a map. The register file my student brought me had three functions and a loop at the bottom, and the loop was the whole program.
The second pass is data. Pick the one variable that the program clearly cares about, usually a list or a dictionary that everything touches, and follow only that. Where is it created, what shape is it at that moment, who adds to it, who reads from it. Ignore everything else on the line. When my student traced the list of names, she found it was being extended inside the loop that was also printing, which was why one name appeared four times. The bug became obvious and she found it herself in about eight minutes.
The third pass is one concrete path. Choose a single realistic input, something small like two names instead of two hundred, and walk the program with it by hand on paper. Write the value of each variable after each step. This is slow and it is the only pass that actually produces understanding. If you cannot do it on paper, insert prints and let the program tell you, which is the same technique we use for hunting bugs.
Most people want to collapse these into one pass. In my experience the collapse costs more time than it saves, because a reader without a map keeps rereading the same twelve lines.
Why read open source code is bad advice at this stage
The standard answer to how do I get better at reading code is to go read a well known open source project. I used to say it myself. I have now watched enough people try it to think it is close to useless for a learner in their first six months, and mildly harmful for the confident ones.
A mature library is not written to be read by a newcomer. It is written to be fast, to cover edge cases nobody mentioned to you, and to survive fifteen years of contributors with different habits. A beginner who opens a popular Python HTTP library finds decorators, abstract base classes, three layers of indirection and a compatibility shim for a version of Python they have never run. They conclude that real code is incomprehensible and that they are not ready, and both conclusions are wrong. One member of our club stopped practising for about three weeks after an afternoon like that.
What works instead is reading code written by people roughly two steps ahead of you. The best source I have found is other learners. At club we swap files deliberately: everyone brings a script they wrote in the last fortnight, and everyone reads somebody else's for twenty minutes before the author says a word. The code is short, the intentions are recoverable, and the author is sitting there to tell you whether you guessed right. That last part is what no open source project can offer.
Your own code from two months ago is the second best source, and it is free. If you cannot follow it, that is information about how you name things rather than a verdict on you.
A reading exercise for one evening
Give this about fifty minutes and do it with a file you did not write, between 40 and 120 lines. Longer than that and the exercise turns into a slog.
- Before opening the file, read its name and the first line of any comment at the top, then write one sentence predicting what it does. You will often be wrong, and noticing the gap later is the useful part.
- Do the shape pass. List every function name and its line count in a notebook. Mark where execution begins.
- Run the program once on the smallest input you can give it, without reading any more of it. Watch what comes out.
- Do the data pass on one variable. Draw arrows between the places that write to it and the places that read it.
- Pick three lines you do not understand and look up only those. Not the whole topic, just the three lines. If a line uses a method you have not met, read the one paragraph of documentation that covers it, which is the habit behind reading Python documentation.
- Change one small thing on purpose and predict the result before you run it. Rename a variable, flip a comparison, reduce a range. A wrong prediction is the fastest way to find the part you still have not understood.
- Write four sentences explaining the file to somebody who has not seen it, and include one thing you still cannot explain. That last sentence is the honest one and it is the one I read first when students send these to me.
My student ran this on her friend's register file and came back with a sentence I liked: it builds a list of names and prints it inside the loop that builds it, so it prints too early. She had not learned any new syntax that week. She had learned to find out what a file does, and the next thing she asked me for was a harder file rather than a tutorial. If you want more structured practice before you try this, the exercises in first steps cover the basics you will meet in most short scripts.
FAQ
How long should reading a short file take?
For a 100 line script with no framework in it, somewhere between thirty and sixty minutes if you are in your first year, and that is a normal speed rather than a slow one. The three passes feel wasteful at first and they get quick after about a dozen files.
Should I read the comments first?
Read them, trust them loosely. Comments drift away from the code they sit next to, because people change a line and leave the sentence above it alone. When a comment and the code disagree, the code is what runs.
What if the code uses things I have not learned yet?
Treat the unknown part as a box with a name and keep going. You can usually work out what a function returns from how its result gets used two lines later, without knowing how it does the work. Opening every box is what turns a fifty minute exercise into a lost weekend.
Is it cheating to ask the author what their code does?
No, though the order matters. Make your guess first, write it down, then ask. Guessing before asking is what trains the skill, and the conversation afterwards is far more useful when you have something specific to be wrong about. The same logic applies to reading a Python error message before pasting it to anyone.
More in First Steps
First Steps
How to Escape Tutorial Hell and Build Something Real
One of our club members turned up last autumn having watched roughly sixty hours of Python video across four months.
First Steps
How to Debug With Print Statements as a Beginner
A student I coach spent most of a Tuesday evening convinced that Python was adding numbers wrong.
First Steps
How to Ask a Coding Question That Gets a Real Answer
A student in my Thursday group spent eleven days stuck on the same program.