1. 错误描述

TypeError: Restaurant() takes no arguments

2. 原因:在编写__init__时,pycharm会自动添加关键字,有时会直接写称整型int, 即__int__。导致错误产生。

————————————————参考————————————————————————————————————————————————————————

3. 错误代码

# 9-1 restaurant
class Restaurant():
def __int__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type def describe_restaurant(self):
print("The " + self.restaurant_name + " have " +
str(self.cuisine_type) + " kinds of food.") def open_restaurant(self):
print("Now is opening.") restaurant = Restaurant("'Restaurant of peace'", 108)
restaurant.describe_restaurant()
restaurant.open_restaurant()

  

4. 正确代码

class Restaurant():
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type def describe_restaurant(self):
print("The " + self.restaurant_name + " have " +
str(self.cuisine_type) + " kinds of food.") def open_restaurant(self):
print("Now is opening.") restaurant = Restaurant("'Restaurant of peace'", 108)
restaurant.describe_restaurant()
restaurant.open_restaurant()

  

  

5.  执行结果

TypeError: Restaurant() takes no arguments的更多相关文章

  1. TypeError: myMethod() takes no arguments (1 given) Python常见错误

      忘记为方法的第一个参数添加self参数 ---------------------------------------------------------------

  2. Python基础-TypeError:takes 2 positional arguments but 3 were given

    Error: 今天写一段简单类定义python代码所遇到报错问题:TypeError: drive() takes 2 positional arguments but 3 were given 代码 ...

  3. python:TypeError: main() takes 0 positional arguments but 1 was given

    TypeError: main() takes 0 positional arguments but 1 was given def main(self): 括号里加上self就好了

  4. Python中错误之 TypeError: object() takes no parameters、TypeError: this constructor takes no arguments

    TypeError: object() takes no parameters TypeError: this constructor takes no arguments 如下是学习python类时 ...

  5. RenderPartial: No overload for method 'Write' takes 0 arguments

    如下方法调用RenderPartial: 报“No overload for method 'Write' takes 0 arguments”的错误: @if (@Model != null &am ...

  6. tensorflow 升级到1.9-rc0,tensorboard 报错:TypeError: GetNext() takes exactly 1 argument (2 given)

    Exception in thread Reloader:Traceback (most recent call last):  File "/usr/lib/python2.7/threa ...

  7. __new__方法以及TypeError: object() takes no parameters的处理

    一些python书或博客将类中的__init__方法称为构造函数,而实际上这种说法是不严格的,因为创建实例的方法是__new__,实例初始化的方法是__init__.__new__方法会返回一个实例, ...

  8. 解决:TypeError: object() takes no parameters

    运行测试用例时发现以下报错 Ran 1 test in 22.505s FAILED (errors=1) Error Traceback (most recent call last): File ...

  9. 【转】python 调用super()初始化报错“TypeError: super() takes at least 1 argument”

    一.实验环境 1.Windows7x64_SP1 2.Anaconda2.5.0 + python2.7(anaconda集成,不需单独安装) 二.实验步骤 2.1 在python中有如下代码: cl ...

随机推荐

  1. Java变量命名规范

    java命名规范 所有方法.变量.类名:见名知意 类成员变量:首字母小写.驼峰原则: 例如:lastName 第一个单词首字母小写,其余首字母大写 局部变量:首字母小写.驼峰原则 类名: 首字母小写. ...

  2. thymeleaf+layui加载页面渲染时报错

    将freemaker替换成thymeleaf时出现以下问题: org.thymeleaf.exceptions.TemplateProcessingException: Could not parse ...

  3. 新来的前端小姐姐问:Vue路由history模式刷新页面出现404问题

    摘要:vue-router 默认 hash 模式 -- 使用 URL 的 hash 来模拟一个完整的 URL,于是当 URL 改变时,页面不会重新加载. 本文分享自华为云社区<学习Vue Rou ...

  4. Python习题集(十四)

    每天一习题,提升Python不是问题!!有更简洁的写法请评论告知我! https://www.cnblogs.com/poloyy/category/1676599.html 题目 请写一个函数,该函 ...

  5. 针对Autocad 2014 第二次安装不上的问题

    针对Autocad 2014 第二次安装不上的问题 1. 以下为卸载过程,不用管. 2. 卸载完之后,右击"开始",点击"运行",得到下图:   并输入:&qu ...

  6. SpringMVC执行流程总结

    SpringMVC 执行流程: 用户发送请求至前端控制器 DispatcherServlet DispatcherServlet 收到请求调用处理映射器 HandlerMapping 处理映射器根据请 ...

  7. dede调用数据时,字符串替换函数使用

    {dede:sql sql="SELECT typename,typedir,typeimg FROM #@__arctype where topid=30 limit 0,6"} ...

  8. 全面分析 Vue 的 computed 和 watch 的区别

    一.computed介绍 computed 用来监控自己定义的变量,该变量在 data 内没有声明,直接在 computed 里面定义,页面上可直接使用. //基础使用 {{msg}} <inp ...

  9. javascript 自定义事件 发布-订阅 模式 Event

    * javascript自定义事件 var myEvent = document.createEvent("Event"); myEvent.initEvent("myE ...

  10. python的列表和java的数组有何异同

    今天面试被问到,自己学习一下. python的列表是可变长的,定义时不需要指定长度:pyhton是弱对象类型,python的列表存储的数据类型可以不相同:python的列表更加灵活,如可以通过''命令 ...