Special Method Protocols

__dir__() — attributes protocol

Customize the names reported by dir(obj). The built-in sorts the returned iterable; this is a discovery aid, not a guarantee of every accessible attribute.

Formal Syntax & Structure

python syntaxpython
def __dir__(self):

Return Value

iterable[str]

Attribute names.

Working Example

Example Snippetpython
class Config:    def __dir__(self): return ["port", "host"]print(dir(Config()))
Python Reference