all Python 3Built-in functionsterm
dir
introspection
Lists the attributes of an object (or the names of the current local namespace).
Syntax
dir([object])
dir() hands back names as strings, not the attributes themselves — reach the value with getattr(obj, name). The list is alphabetised and deliberately approximate: it is built from __dir__ and misses anything a class conjures dynamically in __getattr__. Treat it as a REPL exploration tool, not something program logic should depend on.
Examples
print(dir([])[:5]) # → ? первые пять атрибутов списка (состав зависит от версии Python)
print('append' in dir([])) # → True
class A:
x = 1
def f(self): pass
print('x' in dir(A)) # → True
print('f' in dir(A)) # → True
print(type(dir([]))) # → <class 'list'>
See also
Open in the full glossarydocs.python.orgReport an inaccuracy