Python has three basic layers of namespaces, listed here in order of most specific to most general. Python looks for names in this order and stops looking as soon as it finds the name:
1. Local (names defined inside a class, function, or method)
2. Global (names defined inside a module—often function names and class names, but can be other names, too)
3. Built-in (names that are always available)
If Python can't find a name in any of those places, it raises a NameError exception. If you get an AttributeError, that means that Python found the leftmost (first) name but didn't find the name after the dot. Each object has its own namespace that Python searches. For more information about object namespaces, see Chapters 12 and 13.
Was this article helpful?