I would like to build a class which inherits from a dict and some other classes.
Based on a key of someDict (initial dictionary), Third class should inherit either from First or from Second.
Here is a basic example:
class First(object):
def first_action(self):
print "first_action"
class Second(object):
def second_action(self):
print "second_action"
class Third(dict, First, Second):
"""This is not running code
but, rather, an example of desired functionality.
"""
if "x" == someDict["some_key"]:
third_action == First.first_action()
print third_action
else:
third_action == Second.second_action()
print third_action
A desired output:
obj = Third()
obj.third_action()
'first_action' # <- Should print this value if dict["some_key"] = "x"
'second_action' # <- if someDict["some_key"] != "x"
For more general case Third class, based on the value of a key of someDict, should switch between methods belonging to First or Second.
If action is a method of Third, it should switch between first_action or second_action.
Any suggestion is appreciated!