Python multiple inheritance name clashes [closed]

亡梦爱人 提交于 2019-12-13 09:48:35

问题


I have a question about name clashes in python. If I have something like:

class A: a='a'
class B(A): a='b'
class C(A): a='c'
class D(C,B): pass

D.a will print c, is there any way to retrieve B.a from D or A.a?


回答1:


Yes, you can do exactly what you suggest:

class D(C, B):
    a = A.a


来源:https://stackoverflow.com/questions/20728527/python-multiple-inheritance-name-clashes

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