2006年10月06日 星期五 21:28
Liming_Do,您好!
不行呀。我执行的结果是:
TypeError: super() argument 1 must be type, not classobj
GOOGLE了一下,说是new-style class 的问题,我按照网上查的例子实验也不行。
谁能解释一下吗?
谢谢。
在 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
2006年10月07日 星期六 15:46
2006/10/6, cry <zyqmail在tom.com>: > Liming_Do,您好! > > 不行呀。我执行的结果是: > TypeError: super() argument 1 must be type, not classobj > > GOOGLE了一下,说是new-style class 的问题,我按照网上查的例子实验也不行。 > > 谁能解释一下吗? > > 谢谢。 继承自object的类,或者由这个类派生出来的类,就是new-style类型,所以你可以这样定义你的父类: class A(object): …… -- 云电清华同方小民工
Zeuux © 2025
京ICP备05028076号