2006年10月06日 星期五 18:01
Liming_Do,您好! That's it. Thanks. 在 2006-10-06 16:08:00 您写道: >使用内置函数super(type,obj) > >class A(object): > def meth(self,arg): > print "A's meth - " + arg > >class B(A): > def meth(self,arg): > super(B,self).meth(arg) > print "B's meth - " + arg > >>>>a = A() >>>>b = B() >>>>a.meth('a') >A's meth - a >>>>b.meth('b') >A's meth - b >B's meth - b > >-----Original Message----- >From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn]On Behalf Of Leo Jay >Sent: Friday, October 06, 2006 3:32 PM >To: python-chinese在lists.python.cn >Subject: Re: [python-chinese] how to call parent's method > > >On 10/6/06, cry < zyqmail在tom.com> wrote: > >python,您好! > >我从一个class,继承出一个subclass,override一个method,如何才能从我自己的method中去调用parent class中同名的method呢? > > >如果要用到的话,为什么要用一样的名字呢? > >可以这样: >>>> class A: >.... def test(self): >.... print 'test a' >.... >>>> class B(A): >.... def test(self): >.... print 'test b' >.... def t(self): >.... A.test(self) >.... self.test() >.... >>>> b = B() >>>> b.t() >test a >test b >>>> > > > >-- >Best Regards, >Leo Jay >_______________________________________________ >python-chinese >Post: send python-chinese在lists.python.cn >Subscribe: send subscribe to python-chinese-request在lists.python.cn >Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn >Detail Info: http://python.cn/mailman/listinfo/python-chinese 致 礼! cry zyqmail在tom.com
Zeuux © 2025
京ICP备05028076号