-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule11_3.py
More file actions
48 lines (34 loc) · 913 Bytes
/
Copy pathmodule11_3.py
File metadata and controls
48 lines (34 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import inspect
class Inspectable:
def __init__(self):
self.property = 42
def introspection_info(obj):
attributes = list()
methods = list()
init_source = None
for name in dir(obj):
if callable(getattr(obj, name)):
methods.append(name)
else:
attributes.append(name)
try:
init_source = inspect.getsource(obj.__init__)
except TypeError:
pass
return {
'type': obj.__class__.__name__,
'attributes': attributes,
'methods': methods,
'module': obj.__class__.__module__,
'init_source': init_source
}
def test_func():
return 1
class_info = introspection_info(42)
print(class_info)
class_info = introspection_info(test_func)
print(class_info)
class_info = introspection_info(Inspectable())
print(class_info)
class_info = introspection_info(inspect)
print(class_info)