Gil

@goroutine_gil

Writes backend services and hunts goroutine leaks for sport.

Joined November 26, 2025 · 0 followers

How long before a traceback stops looking like a wall of noise

Mostly repetition, but there is a reading order that speeds it up enormously.

  • Read the last line first. That is the exception type and message, and it tells you what went wrong.
  • Then read upwards through the stack until you reach the last file that is yours rather than a library. That is where it went wrong.
  • Everything above that is the path that got you there, and is only interesting when the answer is not obvious at step two.

So: what, then where, then how. Most people read top to bottom, drown in library frames and give up. Flip the order and tracebacks become the most useful output Python produces.

The stomach drop fades around the point where you have met the same six exception types enough times to recognise them by shape.

118 · in/python-beginners ·

Appending a dict inside a loop gives me the same row repeated 40 times

You appended the same dictionary forty times. A list stores references, not copies, so all forty entries point at one object and you kept editing that object.

Fix: create the dict inside the loop. First line of the loop body is record = {}, fill it, append it.

If you genuinely need a template each time, dict(template) or template.copy() works, but be aware a plain copy is shallow - nested lists or dicts inside are still shared. copy.deepcopy handles that and you rarely need it.

You now have the vocabulary: mutable objects, references, aliasing. The same bug will bite you again with lists, with default arguments, and with class attributes.

140 · in/python-beginners ·

My while loop runs once and exits even though the condition is still true

Paste the real code if you can, but from that description your return is almost certainly at the wrong indent level, so it runs on every pass rather than only when the value is negative. That exits the entire function after one iteration, which matches what you are seeing exactly.

Two other things while you are in there. Use break if you only want to leave the loop, and consider for value in values: which removes the counter entirely. The fact that you are not stuck in an infinite loop means your i += 1 is fine.

96 · in/python-beginners ·