Objects retain info from previous loop iteration
<p>I have a class called <code>run_c</code> which is being used to initialize and execute the run of a kinematics simulation. I assign default values to the attributes of <code>run_c</code>, such as <code>x</code>, before <code>run_c.__init__()</code> is executed. All <code>__init__()</code> is doing is extracting user-input values, aggregated into a dictionary, and assigning them to corresponding attributes in <code>run_c</code> if they exists. For example...</p>

<pre><code>import vars.Defaults as dft
class run_c:

   ...
   dt     = dft.dt
   x      = dft.x0
   states = [ [], [], [], [] ]
   ...

   def __init__(self, input):
      for key in input.keys():
         if hasattr(self, key): setattr(self, key, input[key])
      ...
      self.execute()
</code></pre>

<p><code>run_c.states</code> is a list of lists that is being used to record the values of <code>run_c</code> attributes as they change with timesteps. Later, within <code>run_c.execute()</code>, I am storing <code>x</code> values in <code>states[1]</code>, incrementing the timestep <code>dt</code>, and updating <code>x</code> using velocity and timestep. It's pretty simple stuff, right?...</p>

<p>Here's where the problem begins, though. The first time that the instance of <code>run_c</code> is created, initialized, and executed, it runs perfectly. However, I am operating this simulation by creating, initializing, and executing multiple runs based off of list read from a JSON file. As such, in the driver module...</p>

<pre><code>from Run import run_c
def main():
   ...
   for runEntry in runList:
      currRun = run_c(runEntry)
      ...
   ...
</code></pre>

<p>What happens is that all the values that were stored in <code>run_c.states</code> do not get wiped after each iteration of the loop. I thought that new instances of <code>run_c</code> are being created every time I run the loop so as to execute <code>__init__()</code> fresh with new information. Why are the data values, such as old values for <code>x</code>, being retained after the end of each loop?</p>

<p>Update: When I add in a line of code to reset the values of <code>states</code> back to empty lists within <code>__init__()</code>, the problem goes away. But this shouldn't be a necessary step in what I want to do...should it?</p>