Unfortunately you need to designate a None
default and check inside the method whether it's been passed in
class Sort(object):
def __init__(self, lst):
self.lst = lst
def halve(self, l=None):
if l is None: l = self.lst
n1 = l[:len(l) / 2]
n2 = l[len(l) /2:]
return (n1,n2)
The parameters to a function are established when the function is created, not when it's called, so self.lst
doesn't yet exist.
Also, see the "Principle of Least Astonishment"