J
John Henry
Hi list,
I am trying to understand better Python packaging. This might be a
messed up class hierachy but how would I break this cyclic relatioship?
In file A:
from B import B_Class
Class_A_Main():
def ....
def SomeMethod(self):
res=B_Class(self)
Class_A_SubClass(Class_A_Main):
def ...
In file B:
Class B_Class():
def __init__(self,parent):
...
def SomeMethod(self):
res=C_Class(self)
In file C:
from file A import Class_A_SubClass
Class C_Class(Class_A_SubClass):
def __init__(self, parent):
...
As you can see, the cyclic relationship exists because C_Class is a
sub-class of SubClass which is in turn a sub-class of Class_A_Main and
in one of the methods of Class_A, it has a need to create a C_Class
object.
I tried to merge the files A and C (by placing C_Class behind A_Class)
and have the method in A_Class create C_Class directly but that doesn't
work because Python says C_Class is not defined when it's processing
the A_Class method. May be somebody can tell me how to "forward
declare" a class?
Regards,
I am trying to understand better Python packaging. This might be a
messed up class hierachy but how would I break this cyclic relatioship?
In file A:
from B import B_Class
Class_A_Main():
def ....
def SomeMethod(self):
res=B_Class(self)
Class_A_SubClass(Class_A_Main):
def ...
In file B:
Class B_Class():
def __init__(self,parent):
...
def SomeMethod(self):
res=C_Class(self)
In file C:
from file A import Class_A_SubClass
Class C_Class(Class_A_SubClass):
def __init__(self, parent):
...
As you can see, the cyclic relationship exists because C_Class is a
sub-class of SubClass which is in turn a sub-class of Class_A_Main and
in one of the methods of Class_A, it has a need to create a C_Class
object.
I tried to merge the files A and C (by placing C_Class behind A_Class)
and have the method in A_Class create C_Class directly but that doesn't
work because Python says C_Class is not defined when it's processing
the A_Class method. May be somebody can tell me how to "forward
declare" a class?
Regards,