Python成功解決TypeError: __init__() missing 1 required positional argument: ‘comment‘
原始碼
class Book:
def __init__(self, name, author, comment, state = 0):
self.name = name
self.author = author
self.comment = comment
self.state = state
# 建立一個Book類的子類 FictionBook
class FictionBook(Book):
def __init__(self,name,author,comment,state = 0,type_='虛構類'):
# 繼承並定製父類的初始化方法,增加預設引數 type = '虛構類',讓程式能夠順利執行。
Book.__init__(name,author,comment,state = 0)
self.type=type_
def __str__(self):
status = '未借出'
if self.state == 1:
status = '已借出'
return '型別:%s 名稱:《%s》 作者:%s 推薦語:%s\n狀態:%s ' % (self.type, self.name, self.author, self.comment, status)
book = FictionBook('囚鳥','馮內古特','我們都是受困於時代的囚鳥')
print(book)
報錯型別
line 13, in __init__
Book.__init__(name,author,comment,state = 0)
TypeError: __init__() missing 1 required positional argument: 'comment'
解決方法
Book.__init__
裡面加上self
Book.__init__(self,name,author,comment,state = 0)
self.type=type_
相關文章
- 【已解決】TypeError: __init__() takes 1 positional argument but 2 were givenError
- Python基礎——positional argument vs keyword argumentPython
- Python報錯:TypeError: a bytes-like object is required, not ‘str‘PythonErrorObjectUI
- TypeError: The ‘compilation‘ argument must be an instance of Compilation 報錯Error
- python用pyinstaller生成exe時報錯 TypeError: an integer is required (got type bytes)PythonErrorUIGo
- NILDR is Missing解決方案
- python argument 1 must be 2-item sequence, not intPython
- PB協議報錯 it is missing required fields: (cannot determine missing fields for lite message)協議UI
- Node.js 中 TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]Node.jsErrorImport
- takes 0 positional arguments but 1 was given
- ntldr is missing怎麼解決? ntldr is missing怎麼回事?
- 1.python報錯:TypeError: 'int' object is not subscriptablePythonErrorObject
- Python 錯誤之函式takes 0 positional arguments but 1 was givenPython函式
- main() takes 0 positional arguments but 1 was givenAI
- 解決 CRS-2640: Required resourceUI
- Python安裝MySQL庫詳解(解決Microsoft Visual C++ 9.0 is required )PythonMySqlROSC++UI
- Python3類方法報錯takes 0 positional arguments but 1 was givenPython
- python的__init__()Python
- TypeError: Descriptors cannot not be created directly問題的解決Error
- maven eclipse miss required library解決MavenEclipseUI
- 詳解Python中的__init__和__new__Python
- 詳細解讀Python中的__init__()方法Python
- 解決 TypeError: Type aliases cannot be used with isinstance(). 辦法Error
- -bash: /bin/rm: Argument list too long的解決辦法
- JPA-style positional param was not an integral ordinal錯誤解決辦法
- ntldr is missing怎麼解決 ntldr丟失的解決辦法
- Pycharm:設定完Anaconda後報錯TypeError: an integer is required (got type bytes)PyCharmErrorUIGo
- 安裝sql server managerment studio報錯"The instance id is required but it is missing"SQLServerUI
- Python中__init__的理解Python
- Python__new__和__init__Python
- npm報錯 TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string.Received undefineNPMError
- 刪除大量檔案Argument list too long錯誤解決
- Python中的__init__()方法整理中(兩種解釋)Python
- 詳解Python魔法函式,__init__,__str__,__del__Python函式
- 成功解決building ‘snappy._snappy‘ extension error: Microsoft Visual C++ 14.0 is required. Get it with “BUIAPPErrorROSC++
- Patch 8430622: Required component(s) missing : [ oracle.sysman.top.omsUIOracle
- Python:Python3錯誤提示TypeError: slice indices must be integers or None or have an __index__ method解決辦法PythonErrorNoneIndex
- python中的“__init__”函式Python函式