【发布时间】:2014-06-10 17:07:43
【问题描述】:
如果我必须从B类中的A类重写或继承function2,我该如何完成这种继承?
class A(object):
def function1(self, x, y):
def function2(y):
print "Function 2 ", y
print "Function 1 ", x
function2(y)
class B(A):
def function1(self, x, y):
def function2(y):
print "Before function2"
# Execute class A function2
print "After function2"
# do anything
return super(B,self).function1(x,y)
a = A()
a.function1(10,6)
b = B()
b.function1(11,7)
【问题讨论】:
-
没有“
class A function2”。这是A类中的方法function1的本地方法,如果您不以某种方式将其外部化,我看不到访问它的方法。不过,我可能会监督一些事情。
标签: python class inheritance closures overriding