我在测试python的继承性,我得到了:
__metaclass__=type
class b:
def __init__(s):
s.hungry=True
def eat(s):
if(s.hungry):
print "I'm hungry"
else:
print "I'm not hungry"
class d(b):
def __init__(s):
super(b,s).__init__()
def __mysec__(s):
print "secret!"
obj=d()
obj.eat()
运行时错误如下:
^{pr2}$我无法理解这一点,因为“b”的超类在其init中有s.hungry,而子类在它自己的“init内部调用”super“ 为什么python说“d”对象没有“hungry”属性?在
另一个困惑:错误消息将“d”视为一个对象,但我将其定义为一个类! 我有没有做错什么,怎么做?在
Document:
^{pr2}$我想这就是你想要的:
相关问题 更多 >
编程相关推荐