title: Copying an object in Python
body: <p>I come from a javascript background and while working in Python recently I'm having a bit of trouble with what (in JS) I would have called objects.</p>
  
  <p>I've created a class with an init function that works as expected:</p>
  
  <pre><code>class TestClass(object):
      def __init__(self,var1,var2,...):
          self.var1 = var1
          self.var2 = var2
          ...
  </code></pre>
  
  <p>It may be worth knowing at this point, most of the variables that will be passed in here are actually arrays.</p>
  
  <p>Everything is awesome, I can create instances of this object at will and it works as expected.  For background, I'm doing this:</p>
  
  <pre><code>def make_object(var1,var2,...):
      object = TestClass(var1,var2,...)
      return object
  object1 = make_object(var1, var2,...)
  </code></pre>
  
  <p><code>var1</code>, <code>var2</code> and so on are all arrays which I will work on in-situ later.
  Later in the script I do this:</p>
  
  <pre><code>object2 = object1
  object3 = object1
  </code></pre>
  
  <p>As the values stored in these objects are arrays, I use another variable (worked out in another part of the script) to reduce the arrays down to just the element I need:</p>
  
  <pre><code>object2.var1 = object2.var1[requiredIndex]
  object2.var2 = object2.var2[requiredIndex]
  ...
  </code></pre>
  
  <p>I do this for each array in the object and it sorts the data out perfectly - it was only when I added <code>object3</code> into the whole equation and ran a similar command on it, that I discovered these lines:</p>
  
  <pre><code>object3.var1 = object3.var1[requiredIndex]
  object3.var2 = object3.var2[requiredindex]
  ...
  </code></pre>
  
  <p>...  discovered these lines were operating on the data I'd already refined using the same commands on <code>object2</code>, which I have tested and found has also affected <code>object1</code> so as far as I can tell the three object names are all just references to the same set of data.</p>
  
  <p>I need <code>object2</code> and <code>object3</code> to be independent of each other (and ideally, independent of <code>object1</code>) so how do I go about this?  I hope I've provided enough detail to fully explain my issue.  Cheers in advance!</p>