Inheritance problem

amidzic.branko at gmail.com amidzic.branko at gmail.com
Wed May 9 14:09:28 EDT 2007


I'm trying to solve a problem using inheritance and polymorphism in
python 2.4.2



I think it's easier to explain the problem using simple example:



class shortList:

    def __init__(self):

        self.setList()



    def setList(self):

        a = [1,2,3]

        print a



class longList(shortList):

    def __init__(self):

        shortList.setList()

        self.setList()



    def setList(self):

        a.extend([4,5,6])

        print a



def main():

    a = raw_input('Do you want short or long list? (s/l)')

    if a.upper() == 'S':

        lst = shortList()

    else:

        lst = longList()



    lst.setList()



if __name__ == '__main__':

    main()



After that I'm getting a message:

TypeError: unbound method setList() must be called with shortList
instance as first argument (got nothing instead)



Where is the problem?



Thanks in advance...




More information about the Python-list mailing list