python-3.x - TypeError: __init__() 接受 3 个位置参数,但给了 4 个错误
问题描述
from abc import ABCMeta, abstractmethod
class Book(object, metaclass=ABCMeta):
def __init__(self,title,author):
self.title=title
self.author=author
@abstractmethod
def display(): pass
class MyBook(Book):
def __innit__(self,title,author,price):
self.title = title
self.author = author
self.price = price
def display(self):
print("Title: {0}".format(self.title))
print("Author: {0}".format(self.author))
print("Price: {0}".format(self.price))
title=input()
author=input()
price=int(input())
new_novel = MyBook(title,author,price)
new_novel.display()
遇到错误:TypeError: init () 接受 3 个位置参数,但给出了 4 个,请给我有关如何修复此错误的想法
解决方案
您的第二个启动器函数中有错字。在 MyBook 类中将“ init ”替换为“ init ”。
推荐阅读
- angularjs - 使用 Spring Boot 上传多个文件
- reactjs - Webpack 不提供 React 组件
- firebase - Firebase - 云函数 - “错误:需要使用事件参数调用云函数。”
- html - 在客户端丰富/基于 AJAX 的应用程序中设计登录模块
- netlify - 构建后如何更改 Netlify 文件
- .net - 所有不同的 X509KeyStorageFlags 的基本原理是什么?
- r - 重新编码引用多个向量/列的变量
- react-native - 如何让 MapView.Marker 在 react-native-maps 上显示
- html - 如何在记事本++中删除除html标签和此HTML标签内容之外的所有内容?
- html - 向右滚动时左侧粘性元素消失