我要做的是使用某个命名空间访问继承的方法,例如:
class ExtraMeths(object):
def specialmeth():
pass
class MainClass(ExtraMeths):
def standardmeth():
pass
myclass = MainClass()
myclass.standardmeth() #works
myclass.specialmeth() #also works, but not ideal
现在理想情况下,我想做的是运行myclass.ExtraMeths.specialmeth()
,其中名称ExtraMeths
并不重要,但它位于它自己的主类“属性”中。同样重要的是继承类是继承的,也就是说,相同的self
变量对它可用。你知道吗
原因是有很多方法,我想对它们进行排序,所以将相似的方法分组似乎是有意义的。你知道吗
这应该用合成法来完成:
相关问题 更多 >
编程相关推荐