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 

static method:

class child(object):     @staticmethod     def chunks(l, n):         pass         # coding 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -