user3541631
user3541631

Reputation: 4008

Get a class/instance only declared attributes(not inherited)?

I have 3 classes A,B,C , C inherting form A and B:

class A:
      a = "ala"

class B:
      b = "bla"

class C(A,B):
      c = "cla"

How can I get only the Attributes of C, attributes that are not inherited ?

Upvotes: 0

Views: 45

Answers (1)

timgeb
timgeb

Reputation: 78690

You could access the __dict__ of C directly via the vars builtin.

>>> vars(C)['c']
'cla'
>>> vars(C)['b']
...
KeyError: 'b'

There's not much more to say without further context about what your real problem is.

Upvotes: 2

Related Questions