python - TypeError: method() takes exactly 2 arguments (3 given) -
this question has answer here:
here code:
class child(object): def chunks(l, n): """ yield successive n-sized chunks l. """ in xrange(0, len(l), n): yield l[i:i+n] k= range(1, 10) print k print child().chunks(k,2)
when execute code, python throws following error:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
traceback (most recent call last):
file "/home/sample.py", line 19, in
print child().chunks(k,2)
typeerror: chunks() takes 2 arguments (3 given)
please find snippet !
instance method:
instance method: method defined inside class , belongs current instance of class.
define chunks
method instance method in class.
e.d
class child(object): def chunks(self, l, n): # ^^^ pass # coding
class child(object): @staticmethod def chunks(l, n): pass # coding
Comments
Post a Comment