I would like to implement the following structure:
class Case(nx.Graph):
def __init__(self, case):
if case == 1:
self = Case1()
if case == 2:
self = Case2()
class Case1(Case):
def __init__(self):
super(Case1, self).__init__()
print "Case1"
class Case2(Case):
def __init__(self):
super(Case2, self).__init__()
print "Case2"
For instance, if I create the following object:
graph = Case(1)
a new Object of the class Case1 should be created. In the __init__ of the class Case1 the super() fuction should call the __init__ function of the networkx.Graph().
If I run that code, the result should be a networkx.Graph object called "graph" and it should print Case1.
case = Case(x), you expect to get an instance ofCase, not any other class. Have plainCase1andCase2classes, even if they inherit from a common parent, and leave the decision which class to construct outside any of those classes.Class.__init__is only called on a new object ifClass.__new__actually returns an instance ofClass.