I hope you’re doing well. I am writing this message, because I would like to have access to all the attributes written of an object. So in this case, below I would like to access the value of self.name, the value of self.age and the value of self.sex .
I tried with dir(self) but it doesn’t give me just these 3 above
class test(object):
def __init__(self,uut):
self.name="name"
self.age= "age"
self.sex="male"
self.cross_count = ccc.cross((att, getattr(self,att)) for att in dir(self))
>Solution :
All of them are under __dict__
class test(object):
def __init__(self):
self.name = "name"
self.age = "age"
self.sex = "male"
att = [(k, v) for k, v in (self.__dict__.items())]
# __dict__ is just a simple python dictionary. You can use .values() if you want only values
values = [v for v in (self.__dict__.values())]
print(att)
test()