Command Line Arguments and Exit Codes
sys.argv holds what the user typed, stdout carries results, stderr carries problems, and the exit code tells the shell whether it worked.
968 published notes across every category.
sys.argv holds what the user typed, stdout carries results, stderr carries problems, and the exit code tells the shell whether it worked.
argparse turns a description of your options into a parser, a validator and a help page. It is the standard way to give a Python script a real interfa...
A test is a small program that checks another program. unittest ships with Python, finds your tests automatically and tells you exactly what broke.
Reading the traceback, forming a hypothesis and checking it. The debugger is a tool; the method is what actually finds the bug.
Code is read far more often than it is written. Consistent style, honest names and clear structure are what make the second reading cheap.
Annotations describe what a function expects and returns. Python does not enforce them, and that is the point: they are documentation a tool can check...
Type variables let one function work with any type while keeping the relationship between input and output. Protocol describes a shape, and TypedDict...
Big-O describes how work grows with input size. Choosing the right container is worth more than every micro-optimisation combined.
Measure before optimising. Guessing where a program spends its time is wrong often enough that the habit is worth breaking permanently.
Once the algorithm is right, a handful of techniques reliably help: build less, look up less, let C do the loop, and cache what repeats.
Most security problems come from trusting input, trusting paths and storing secrets in the wrong place. Each has a standard, boring, correct answer.
eval, exec, shell commands, string built queries and pickle all take text and turn it into action. Each has a safe alternative that costs almost nothi...