consider class
class Grid():
def __init__(self,r,z,t):
self.rgrid = r
self.zgrid = z
self.tgrid = t
self.otherstuff = long_computation(r,t,z)
class Solution(Grid):
def __init__(self,r,g):
self.zones = r
Grid.__init__(self,g.r,g.z,g.t)
g = Grid(my_r,my_z,my_t)
sol = Solution(r,g)
This creates what I want, except the "long_computation" is done twice. What would be a clean way to structure the classes that would work whether I called just Grid, or whether I also did the Solution step?
Thanks, J.
Solutioninherit fromGrid, and why does it take an existingGridas an argument instead ofr,z, andt?rinGrid.__init__and inSolution.__init__? it seems like last one should be namedzonesdone_long_computationwhich you'd set the first time__init__is executed, and__init__checks ifdone_long_computationis set.