2015-04-04 17:05:30 -04:00
|
|
|
# test builtin dir
|
|
|
|
|
|
|
|
# dir of locals
|
|
|
|
print('__name__' in dir())
|
|
|
|
|
|
|
|
# dir of module
|
|
|
|
import sys
|
2021-04-23 15:26:42 -04:00
|
|
|
print('version' in dir(sys))
|
2015-04-04 17:05:30 -04:00
|
|
|
|
2016-12-19 22:08:27 -05:00
|
|
|
# dir of type
|
|
|
|
print('append' in dir(list))
|
|
|
|
|
2015-12-28 23:03:15 -05:00
|
|
|
class Foo:
|
|
|
|
def __init__(self):
|
|
|
|
self.x = 1
|
|
|
|
foo = Foo()
|
|
|
|
print('__init__' in dir(foo))
|
|
|
|
print('x' in dir(foo))
|
|
|
|
|
2018-02-15 02:12:27 -05:00
|
|
|
# dir of subclass
|
|
|
|
class A:
|
|
|
|
def a():
|
|
|
|
pass
|
|
|
|
class B(A):
|
|
|
|
def b():
|
|
|
|
pass
|
|
|
|
d = dir(B())
|
|
|
|
print(d.count('a'), d.count('b'))
|
|
|
|
|
|
|
|
# dir of class with multiple bases and a common parent
|
|
|
|
class C(A):
|
|
|
|
def c():
|
|
|
|
pass
|
|
|
|
class D(B, C):
|
|
|
|
def d():
|
|
|
|
pass
|
|
|
|
d = dir(D())
|
|
|
|
print(d.count('a'), d.count('b'), d.count('c'), d.count('d'))
|