Get all attributes of a class in Python

Is it possible to get all the attributes of some class or object? I have a class with many attributes and I want to create a function / method that returns all attributes of an object to be None.

Since there are many of these attributes, I must avoid writing them all to the function.

Something like that:

def get_all_empty_attributes(self):
    for attr  in self.attributes.names:
        if self.attr==None:
            yield attr

      

Can built-in functions be used?

+3


source to share


1 answer


Use vars



for property, value in vars(your_class).iteritems():
    print(property, ":", value)

      

+1


source







All Articles