I have two files : my_file.py and test.py.
my_file.py :
def heelo_friends():
random_var = 56
class Attack:
ss = 741
def the_function():
pass
test.py :
import my_file as mf
import inspect
import sys
def get_classes(self) -> list:
classes = []
for x in dir(mf):
obj = getattr(mf,x)
if inspect.isclass(obj):
classes.append(x)
return f"All classes : {classes}"
# All classes : ['Attack']
This file get all Classes from my_file.py.
Now I want get all attributes from this classes (vars/methods etc ...)
How can I do that with inspect module ?
Here is a solution using
inspect.getmembers:Output: