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
- missing ) after argument list
- find: missing argument to `-exec'
- 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
- Node.js 中 TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]Node.jsErrorImport
- python argument 1 must be 2-item sequence, not intPython
- Python安裝MySQL庫詳解(解決Microsoft Visual C++ 9.0 is required )PythonMySqlROSC++UI
- 1.python報錯:TypeError: 'int' object is not subscriptablePythonErrorObject
- 成功解決building ‘snappy._snappy‘ extension error: Microsoft Visual C++ 14.0 is required. Get it with “BUIAPPErrorROSC++
- Python3類方法報錯takes 0 positional arguments but 1 was givenPython
- Pycharm:設定完Anaconda後報錯TypeError: an integer is required (got type bytes)PyCharmErrorUIGo
- JPA-style positional param was not an integral ordinal錯誤解決辦法
- 解決 TypeError: Type aliases cannot be used with isinstance(). 辦法Error
- TypeError: Descriptors cannot not be created directly問題的解決Error
- Python中__init__的理解Python
- Missing required icon file. The bundle does not contain an app icon for iPhone / iPod Touch of ex...UIAIAPPiPhone
- 解決 The ‘supervisor==3.2.0‘ distribution was not found and is required by the application錯誤UIAPP
- 詳解Python魔法函式,__init__,__str__,__del__Python函式
- Python中的__init__()方法整理中(兩種解釋)Python
- npm報錯 TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string.Received undefineNPMError
- Python:Python3錯誤提示TypeError: slice indices must be integers or None or have an __index__ method解決辦法PythonErrorNoneIndex
- 【問題解決】property [elasticsearch.version] is missing for plugin [head]ElasticsearchPlugin
- 刪除大量檔案Argument list too long錯誤解決
- 問題解決:TypeError: unsupported format string passed to NoneType.__format__ErrorORMNone
- Python中__init__的用法和理解Python
- 使用命令登入harbor報錯authentication required解決方法UI
- python 詳解類class的繼承、__init__初始化、super方法Python繼承
- Python __new__ 和 __init__ 的區別Python
- 解決Chrome外掛安裝時報錯:“Manifest file is missing or unreadable“Chrome
- Python 中__init__函式以及引數selfPython函式
- python中__init__ 和__new__的對比Python
- Neovim中提示Error: Required vim compiled with +pythonErrorUICompilePython
- oracle comment on的用法Oracle
- pragma comment的使用
- git push出現unpack failed: error Missing tree錯誤的解決方法GitAIError
- Eclipse解決Project中Java Build Path 提示 2 build peth entriesare missing.EclipseProjectJavaUI