Suppose I have a Class that's passed a set of options.
For example:
class Thing(object):
def __init__(self, options):
self.name = options['name']
if options['material'] == 'organic':
self.living = options['living']
if self.living:
self.kingdom = options['kingdom']
else:
self.material = options['material']
So if it's material and organic, it will have an additional option specifying if it's living, if it's living it will also have a kingdom etc.
Suppose I want to define a function in class Thing that will for example:
def belongToKingdom(self):
print self.kingdom
But I only want such a function defined at __init__ if kingdom is passed in options, otherwise ignored. What's the correct way to accomplish this ?
class LivingThing(Thing):?