[英]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.