在此处使用的形式中,您将明确指定
method_two要调用的类的静态对象。如果这
method_three是一个类方法,并且您调用
cls.method_two,则会得到所需的结果:
class Test: def method_one(self): print "Called method_one" @staticmethod def method_two(): print "Called method_two" @classmethod def method_three(cls): cls.method_two()class T2(Test): @staticmethod def method_two(): print "T2"a_test = Test()a_test.method_one() # -> Called method_onea_test.method_two() # -> Called method_twoa_test.method_three() # -> Called method_twob_test = T2()b_test.method_three() # -> T2Test.method_two() # -> Called method_twoT2.method_three() # -> T2
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)