dimanche 22 juillet 2018

Python, How to get for class level attributes only

I have a class like this:

class foo(object):
    iattr = 'iattr'
    def __init__(self):
        self.ival = 'ival'

ca = foo()

After vars(ca), I get below {'ival': 'ival'}.

I want to get a dict of class level attributes only, without instance attributes.

i.e. {'iattr': 'iattr'}

thanks a lot.





Aucun commentaire:

Enregistrer un commentaire