Special Method Protocols

__getattribute__() — attributes protocol

Intercept ordinary instance attribute reads, including existing names. Delegate to object.__getattribute__ to avoid recursive lookup. Implicit special-method dispatch may bypass instance attribute interception.

Formal Syntax & Structure

python syntaxpython
def __getattribute__(self, name):

Parameters & Attributes

NameTypeDescription
namestrRequested attribute name.

Return Value

object

Resolved attribute value.

Working Example

Example Snippetpython
class Config:    port = 80    def __getattribute__(self, name):        if name == "port": return 443        return object.__getattribute__(self, name)print(Config().port)
Python Reference