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中Scanner用法总结

    最近在做OJ类问题的时候,经常由于Scanner的使用造成一些细节问题导致程序不通过(最惨的就是网易笔试,由于sc死循环了也没发现,导致AC代码也不能通过...),因此对Scanner进行了一些总结整 ...

  2. GoLang设计模式01 - 建造者模式

    建造者模式是一种创建型模式,主要用来创建比较复杂的对象. 建造者模式的使用场景: 建造者模式通常适用于有多个构造器参数或者需要较多构建步骤的场景.使用建造者模式可以精简构造器参数的数量,让构建过程更有 ...

  3. php open_basedir绕过

    描述 php为了安全性考虑,有一项 open_basedir 的设置,它可将用户访问文件的活动范围限制在指定的区域.根据你web服务器环境,open_basedir可以在几个地方设置. 首先 在php ...

  4. 使用 baget 搭建私有 nuget 私有服务

    现在几乎所有语言都提供包管理工具,比如 JavaScript 的 npm ,Java 的 Maven ,Dart 的 pub ..Net 程序当然是 NuGet .NuGet 也出现很多年了,奇怪的是 ...

  5. JDK1.8源码(五)——java.util.Vector类

    JDK1.8源码(五)--java.lang. https://www.cnblogs.com/IT-CPC/p/10897559.html

  6. WEB漏洞——XXE

    XXE漏洞又称XML外部实体注入(XML External Entity) 介绍XXE漏洞前先说一下什么是XML XML语言 XML用于标记电子文件使其具有结构性的标记语言,可以用来标记数据定义数据类 ...

  7. ELK学习之Logstash篇

    Logstash在ELK这一整套解决方案中作为数据采集终端,支持对接Kafka.数据库(MySQL.Oracle).文件等等. 而在Logstash内部的数据流转,主要经过三个环节:input -&g ...

  8. 【第一篇】- Maven 系列教程之Spring Cloud直播商城 b2b2c电子商务技术总结

    Maven 教程 Maven 翻译为"专家"."内行",是 Apache 下的一个纯 Java 开发的开源项目.基于项目对象模型(缩写:POM)概念,Maven ...

  9. mysql中通过sql语句查询指定数据表的字段信息

      mysql数据库在安装完成时,自动创建了information_schema.mysql.test这三个数据库.其中,information_schema记录了创建的所有数据库的相关信息,因此可以 ...

  10. Docker部署启动错误,需要手动进入Docker的容器里,启动程序,排查错误

    #docker-compose build --no-cache //重新创建容器,不管有没有 #docker-compose up #docker-compose up -d //后台启动并运行容器 ...