This code:
class testclass:
def __init__(self,x,y):
self.x = x
self.y = y
self.test()
def test():
print(\'test\')
i
Python always passes the instance as the first argument of instance methods, this means that sometimes the error messages concerning the number of arguments seems to be off by one.
class testclass:
def __init__(self,x,y):
self.x = x
self.y = y
self.test()
def test(self): ## instance method
print('test', self)
if __name__ == '__main__':
x = testclass(2,3)
If you don't need access to the class or the instance, you can use a staticmethod as shown below
class testclass:
def __init__(self,x,y):
self.x = x
self.y = y
self.test()
@staticmethod
def test():
print('test')
if __name__ == '__main__':
x = testclass(2,3)
A classmethod is similar, if you need access to the class
, but not the instance
class testclass:
def __init__(self,x,y):
self.x = x
self.y = y
self.test()
@classmethod
def test(cls):
print('test', cls)
if __name__ == '__main__':
x = testclass(2,3)