Iterate trough Python object properties

So I’m learning Python and I must say one of the most useful code snippets I found was this for loop to iterate trough object properties:

for attr in dir(checkbox):
    print("obj.%s = %r" % (attr, getattr(checkbox, attr)))

I read that there are many 3rd-party libraries who add things like exception handling, recursing into nested objects, special characters printing and etc. But as I understand they all basically do this thing.

Leave a comment

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