TypeError: Restaurant() takes no arguments
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的更多相关文章
- TypeError: myMethod() takes no arguments (1 given) Python常见错误
忘记为方法的第一个参数添加self参数 ---------------------------------------------------------------
- Python基础-TypeError:takes 2 positional arguments but 3 were given
Error: 今天写一段简单类定义python代码所遇到报错问题:TypeError: drive() takes 2 positional arguments but 3 were given 代码 ...
- 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就好了
- Python中错误之 TypeError: object() takes no parameters、TypeError: this constructor takes no arguments
TypeError: object() takes no parameters TypeError: this constructor takes no arguments 如下是学习python类时 ...
- RenderPartial: No overload for method 'Write' takes 0 arguments
如下方法调用RenderPartial: 报“No overload for method 'Write' takes 0 arguments”的错误: @if (@Model != null &am ...
- 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 ...
- __new__方法以及TypeError: object() takes no parameters的处理
一些python书或博客将类中的__init__方法称为构造函数,而实际上这种说法是不严格的,因为创建实例的方法是__new__,实例初始化的方法是__init__.__new__方法会返回一个实例, ...
- 解决:TypeError: object() takes no parameters
运行测试用例时发现以下报错 Ran 1 test in 22.505s FAILED (errors=1) Error Traceback (most recent call last): File ...
- 【转】python 调用super()初始化报错“TypeError: super() takes at least 1 argument”
一.实验环境 1.Windows7x64_SP1 2.Anaconda2.5.0 + python2.7(anaconda集成,不需单独安装) 二.实验步骤 2.1 在python中有如下代码: cl ...
随机推荐
- 分布式ID生成器及redis,etcd分布式锁
分布式id生成器 有时我们需要能够生成类似MySQL自增ID这样不断增大,同时又不会重复的id.以支持业务中的高并发场景.比较典型的,电商促销时,短时间内会有大量的订单涌入到系统,比如每秒10w+.明 ...
- skynet 开启 https 配置
修改 Makefile Mac 下: # https : turn on TLS_MODULE to add https support TLS_MODULE=ltls TLS_LIB="$ ...
- Django——Paginator分页功能练习
1.路由urls.py from django.contrib import admin from django.urls import path from app01.views import in ...
- HCNP Routing&Switching之动态路由协议IS-IS基础
前文我们了解了OSPF的特殊区域相关话题,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/15236330.html:今天我们来聊一聊另一动态路由协议IS-IS相 ...
- Apache网页优化
目录: 一.Apache网页优化概述 二.网页压缩 三.网页缓存 四.隐藏版本信息 五.Apache防盗链 一.Apache网页优化概述 在企业中,部署Apache后只采用默认的配置参数,会引发网站很 ...
- IO流实现简单的文件的剪切
思路: 判断 即将 复制的文件是文件夹还是文件 遍历需要复制的源文件夹 如果是文件夹,就通过流创建一个同样的子文件夹 如果是文件,就复制过去 接下来上代码 public class Demo1 { p ...
- 使用私有gitlab发布自动生成版本号和标签(version和tag)(骚)
设置 semantic ,自动生成版本号和标签 FROM node:14-buster-slim LABEL maintainer="wangyunpeng" COPY sourc ...
- Django学习day06随堂笔记
每日测验 """ 今日考题 1.什么是FBV与CBV,能不能试着解释一下CBV的运作原理 2.模版语法的传值需要注意什么,常见过滤器及标签有哪些 3.自定义过滤器,标签, ...
- Java基础系列(34)- 什么是数组
数组的定义 数组是相同类型数据的有序集合 数组描述的是相同类型的若干个数据,按照一定的先后次序排列组合而成 其中,每一个数据称作一个数组元素,每个数组元素可以通过一个下标来访问它们
- Linux系列(22) - 用户登录查看命令
需求 查看当前在线用户情况:历史用户登录情况 W 格式 [root@localhost ~]# w:查看所有登录用户信息 [root@localhost ~]# w [用户名]:查看指定登录用户信息 ...