# Attribute Lookup (\_\_getattr\_\_)

say it: **“AT-rih-byoot LUK-up”** **/ˈætrɪbjut ˈlʊkʌp/** or **“DUN-der GET-at-er”** **/ˈdʌndər ˈɡɛtˌætər/**

Runs when code asks for an attribute that doesn't exist.

## What does `__getattr__` do?

`__getattr__` runs when code asks for an attribute that doesn't exist, so you can answer anyway. It's used for things like config objects and wrappers.

```python
class Config:
    def __init__(self, values):
        self._values = values

    def __getattr__(self, name):
        return self._values.get(name, "not set")

settings = Config({"theme": "dark"})
print(settings.theme)     # dark
print(settings.language)  # not set
```

Level: Master · [More Python terms at this level](https://www.ask-codey.com/glossary?category=python&level=5)

Updated: November 17, 2026

Source: https://www.ask-codey.com/glossary/attribute-lookup-getattr
