0

Here is a code:

class Child(object):
    def chunks(l, n):
        """ Yield successive n-sized chunks from l.
        """
        for i in xrange(0, len(l), n):
            yield l[i:i+n]

k= range(1, 10)
print k
print Child().chunks(k,2)

When I execute this 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 exactly 2 arguments (3 given)

Please find my snippet !

Jay Venkat
  • 397
  • 2
  • 5
  • 18

1 Answers1

2

Instance method: A method that is defined inside a class and belongs only to the current instance of a class.

Define chunks method as instance method in class.

e.d

class Child(object):
    def chunks(self, l, n):
        #      ^^^   
        pass
        # do coding

Static Method:

class Child(object):
    @staticmethod
    def chunks(l, n):
        pass
        # do coding
Justapigeon
  • 560
  • 1
  • 8
  • 22
Vivek Sable
  • 9,938
  • 3
  • 40
  • 56