Every time a function is called, Python makes a frame: a record of that call, with its own local variables, its place in the code and a link to the frame that called it. The frames form the call stack. Names are looked up in dictionaries called namespaces, and so are attributes. This lesson shows frames and namespaces as real objects that you can inspect, and spells out the exact order in which Python looks for a name and for an attribute.
More lessons in Complete Python Programming