I am trying to write a data processing script and I think I'm misinterpreting the structure of Object Oriented Programming in Python.
I have sets of simulations that keep some variables constant and others which change according to the sim. I'm trying to contain the set of sims in a parent object and include a list of sims as an attribute, which are defined as a child object:
class Sim_set(path) :
def __init__ :
f = open(path)
self.fixed_attributes = fixed_attributes(f)
sims = [Sim(data) for data in f]
class Sim(Sim_set) :
def __init__(data) :
Sim_set.__init__()
self.variable_attributes = variable_attributes(data)
def derived_attributes() :
self.derived_attributes = math(self.variable_attributes,self.fixed_attributes)
The problem is that it looks like for each Sim, a new instance of Sim_set is created, when in reality I want the opposite: I want a single instance of Sim_set, with attributes that Sim can fetch, and many instances of Sim, contained in Sim_set.
I apologize if this is a rather broad question, but am I doing this right?
EDIT: So based on the answers so far, what I'm doing now is:
So what I am doing now is :
class Sim :
def __init__(data,sim_set) :
self.sim_set = sim_set
self.var_attr = f(data)
def deriv_attr() :
self.deriv_attr = g(self.var_attr,self.sim_set.fixed_attr)
It seems to work, but the crux of the question is really, "is this a good habit to have"?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…