[英]Cython error: Cannot convert Python object to type 'int *' error, when passing an Integer array to a function
[英]Type Error when passing an object into a function
對於學校項目,我正在為當地托兒所創建計費系統。 每張賬單都是一個對象,具有屬性startmonth
(第一個月endmonth
)、 endmonth
(最后一個月childName
)和childName
。
class calculate_bill:
def __init__(self, startmonth, endmonth, childName):
self.startmonth = startmonth
self.endmonth = endmonth
self.childName = childName`
我使用了 tkinter 下拉菜單來獲取所需的月份並將所選月份傳遞給函數。 但是,當我嘗試運行它時,出現錯誤;
類型錯誤:startmonth() 缺少 1 個必需的位置參數:'bill'
不確定這意味着什么或如何解決它。 任何建議將不勝感激
def startmonth(self, m1, bill):
bill.startmonth = m1
print(bill.startmonth)
我正在嘗試理解您共享的代碼,並且我假設startmonth
是calculate_bill
類的一個方法,到目前為止一切正常,但是您缺少兩件事:
您的函數和類屬性不明確, startmonth
是屬性和方法的名稱。 將兩者之一更改為其他內容。
函數startmonth
已經收到賬單:它被稱為self
,所以你不需要將bill
作為參數傳遞。 實例方法的第一個參數總是它自己,傳統上稱為self
,盡管不一定。
這是您嘗試執行的操作的更有效表示:
class CalculateBill:
def __init__(self, startmonth, endmonth, childName):
self.startmonth = startmonth
self.endmonth = endmonth
self.childName = childName`
def set_startmonth(self, m1):
self.startmonth = m1
print(self.startmonth)
關於此代碼的一些提示:
set_startmonth
不需要bill
參數。 它已經有了它,帶有self
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.