Listing Python class attributes

If you have a class (let’s call it TestClass) and you need to see what attriutes are defined in it, make a class object and then use the __dict__ command.

m = TestClass()
m.__dict__

that will give you a dictionary of the attribute names/values. This is really helpful if the class lacks good documentation.

Leave a Reply

Your email address will not be published. Required fields are marked *