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

北战南征 提交于 2019-12-25 02:24:10

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/52127112/get-a-class-instance-only-declared-attributesnot-inherited

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!