找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2452|回复: 2

[已解决] python从入门到实战,9.6题,学习继承,求助哪里出问题老了

4

主题

7

帖子

7

积分

贫民

积分
7
mothecoolest 发表于 2019-7-25 18:36:40 | 显示全部楼层 |阅读模式
本帖最后由 mothecoolest 于 2019-7-26 10:07 编辑

代码:
class Restaurant():
    """A simple attempt to model a restaurant"""
    def  __init__(self,name,type):
        """Initialize name and type of a restaurant."""
        self.name=name
        self.type=type

    def describe_restaurant(self):
        """describe restaurant"""
        print("The restaurant is called "+ self.name.title() +" and it serves "
         + self.type + " food.")
    def open_restaurant(self):
        """tell people the restaurant is open"""
        print(self.name.title() + " is open!")
class Ice_cream(Restaurant):
    """A model of ice cream stand inherance from Class Restaurant"""
    def __init__(self,name,type):
        """Initialize attributes of Restaurant"""
        super.__init__(name,type)
    def describe_icecream(self):
        """describe restaurant"""
        print("The ice cream stand is called "+ self.name.title() +" and it serves "
         + self.type + " of ice cream.")

my_ice_cream=Ice_cream('Mooth','Chocolate')



错误反馈:
Traceback (most recent call last):
  File "9_5.py", line 25, in <module>
    my_ice_cream=Ice_cream('Mooth','Chocolate')
  File "9_5.py", line 19, in __init__
    super.__init__(name,type)
TypeError: descriptor '__init__' requires a 'super' object but received a 'str'

回复

使用道具 举报

26

主题

84

帖子

84

积分

新手

积分
84
银发的index 发表于 2019-7-27 10:27:02 | 显示全部楼层
跟踪错误栈,你super忘了调用了
super().__init__(name,type)
首先遇到错误请自己查看错误栈确定是拼写错误还是什么,搞不明白再问
回复 支持 反对

使用道具 举报

4

主题

7

帖子

7

积分

贫民

积分
7
mothecoolest  楼主| 发表于 2019-7-27 14:47:10 | 显示全部楼层
银发的index 发表于 2019-7-27 10:27
跟踪错误栈,你super忘了调用了
super().__init__(name,type)
首先遇到错误请自己查看错误栈确定是拼写错误 ...

谢谢, 自己发现了问题,想要删帖结果不会,以为改成已解决就不会浪费大家时间了。抱歉 谢谢
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表