- 论坛徽章:
- 2
|
- __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()
复制代码 运行有错误,说是:
- Traceback (most recent call last):
- File "2.py", line 17, in ?
- obj.eat()
- File "2.py", line 6, in eat
- if(s.hungry):
- AttributeError: 'd' object has no attribute 'hungry'
复制代码 这个我就不能理解了,超类有__init__调用设置s.hungry,子类的__init__也已经调用了super来初始化
为什么还说d这个对象(而不是类)没有一个attribute叫做hungry?
错误信息把d当成了一个object,这也是我不理解的。
求解释!
|
|