title: Bizarre reference behavior in Tree implementation
body: <p>I've been completely perplexed by a bug in a larger system. Consider this class (each node maintains a pointer to its parent and a list of its children):</p>
  
  <pre><code>class Node:
      children = []
  
      def __init__(self, parent):
          self.contents = dict()
          self.parent = parent
  
          if parent is not None:
              print self.children
              print parent == self
              parent.children.append(self)
              print self.children
  </code></pre>
  
  <p>Running this:</p>
  
  <pre><code>foo1 = Node(None)
  foo2 = Node(foo1)
  </code></pre>
  
  <p>Mysteriously returns this:</p>
  
  <pre><code>[]
  False
  [&lt;__main__.Node instance at 0x10051f128&gt;]
  </code></pre>
  
  <p>How does this make any sense whatsoever? Why is the second node's children not empty? Perhaps I'm missing a basic understanding of a concept related to how Python passes references around.</p>