Polymorphism the Python way

Daniel Klein danielk at aracnet.com
Sun Aug 31 05:55:30 CEST 2003

Given the following code,,,

class Dead(object):
    def __init__(self, adeadthing):
        self.deadthing = adeadthing

    def getthing(self):
        return self.deadthing

class Parrot(object):
    def __init__(self, aparrotthing):
        self.parrotthing = aparrotthing

    def getthing(self):
        return self.parrotthing

...and then somewhere in some script I use...


to get whatever 'thing' I want to get.

Isn't there a better way to do this in Python? I hate doing these
'get' type methods. The seem ugly to me.

Daniel Klein


More information about the Python-list mailing list