title: Python object containing an array of objects being weird
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/68645/static-class-variables-in-python">Static class variables in Python</a><br>
    <a href="https://stackoverflow.com/questions/2878499/python-oop-and-lists">Python OOP and lists</a>  </p>
  </blockquote>
  
  
  
  <p>just wondering if I could get some help on this.</p>
  
  <p>I am using python, and have hit an obstacle that I can't seem to figure out with a small program I am working on. Here is my problem (using a very simple and unrelated example): I have a class:</p>
  
  <pre><code>class dog:
      name = ''
      friends = []
  </code></pre>
  
  <p>I make a couple objects from it:</p>
  
  <pre><code>fido = dog()
  rex = dog()
  </code></pre>
  
  <p>And here is where I get stuck. I don't know why this is happening and I haven't figured it out. I'm assuming my understanding of something is deficient though, any explanation would be great. So here is my problem, if I append one object to the other (which seems like it should work just fine):</p>
  
  <pre><code>fido.friends.append(rex)
  </code></pre>
  
  <p>... things mess up. As you can see here:</p>
  
  <pre><code>&gt;&gt;&gt; fido.friends.append(rex)
  &gt;&gt;&gt; fido.friends
  [&lt;__main__.dog instance at 0x0241BAA8&gt;]
  &gt;&gt;&gt; rex.friends
  [&lt;__main__.dog instance at 0x0241BAA8&gt;]
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>That just deosn't make sense to me. Shouldn't only fido.friends have something in it? Even if I make a new object:</p>
  
  <pre><code>rover = dog()
  </code></pre>
  
  <p>It has a dog instance in it, which we can see is our 'rex' object.</p>
  
  <pre><code>&gt;&gt;&gt; rex.name = "rex"
  &gt;&gt;&gt; fido.friends[0].name
  'rex'
  &gt;&gt;&gt; rex.friends[0].name
  'rex'
  &gt;&gt;&gt; rover.friends[0].name
  'rex'
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>This just isn't making sense, and I'd love some help. I searched around for awhile trying to find an explanation, but didn't. Sorry if there is a similar question I missed.</p>