Special Method Protocols
__delattr__() — attributes protocol
Intercept del obj.name and delattr(). Delegate to object.__delattr__ for ordinary deletion. Returning a value does not make it the result of a del statement.
Formal Syntax & Structure
python syntaxpython
def __delattr__(self, name):Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | str | Name to delete. |
Return Value
None
No meaningful result.
Working Example
Example Snippetpython
class Config: def __delattr__(self, name): if name == "locked": raise AttributeError("locked") object.__delattr__(self, name)
def demo(): c=Config(); c.temp=7; del c.temp return hasattr(c,"temp")print(demo())