掌握蟒蛇接力误差超

掌握蟒蛇接力误差超

问题描述:

我想这掌握蟒蛇接力误差超

In [1]: class Parent: 
    ...:  def __init__(self): 
    ...:   self.a =10 
    ...:   self.b =20 
    ...: 


In [3]: class NewParent(Parent): 
    def __init__self(): 
     super(NewParent,self).__init__() 
     self.c =30 
    ...: 

当我这样做

In [4]: c = NewParent() 

In [5]: c 
Out[5]: <__main__.NewParent instance at 0x2c98878> 

In [6]: c.a 
Out[6]: 10 

In [7]: c.b 
Out[7]: 20 

In [8]: c.c 

AttributeError的回溯(最近最后一次通话)在 () - - > 1 cc

AttributeError:NewParent实例没有属性'c'

+0

是'init'方法一样'高清__init__self():'在你的代码?或者这是这里的错字? – 2013-02-09 09:11:48

您伪造了NewParent上的方法声明。

def __init__(self): 
+0

现在我得到这个'TypeError:必须是类型,而不是classobj'超级行 – user196264097 2013-02-09 09:37:50

+0

@ user9:那是因为你没有让'Parent'成为一种新式的类。使它从'object'派生。 – 2013-02-09 09:59:12

+0

感谢的人,我得到 – user196264097 2013-02-09 10:21:29

class NewParent(Parent): 
    def __init__self(): 
     super(NewParent,self).__init__() 
     self.c =30 

应该

class NewParent(Parent): 
    def __init__(self): 
     #Your code here 
+0

现在我得到这个'TypeError:必须是类型,而不是classobj超级行' – user196264097 2013-02-09 09:41:37