我在这里看到了一些关于我的错误的答案,但它对我没有帮助。我是一个绝对的noob在Python上的类,并刚刚在9月份开始执行此代码。反正看看我的代码TypeError:__init __()只需要3个参数(给出2个参数)
class SimpleCounter():
def __init__(self, startValue, firstValue):
firstValue = startValue
self.count = startValue
def click(self):
self.count += 1
def getCount(self):
return self.count
def __str__(self):
return 'The count is %d ' % (self.count)
def reset(self):
self.count += firstValue
a = SimpleCounter(5)
,这是错误我得到
Traceback (most recent call last):
File "C:\Users\Bilal\Downloads\simplecounter.py", line 26, in <module>
a = SimpleCounter(5)
TypeError: __init__() takes exactly 3 arguments (2 given
据透露,你的类应该从'object'继承(谷歌的蟒蛇新样式类,如果你是好奇,为什么) – ThiefMaster 2012-02-25 14:54:56