title: Python's initialization a list in a class
body: <p>I don't understand python's behavior, I've got many the same errors:</p>
  
  <blockquote>
    <p>File "./start.py", line 20, in print2<br>
       item.print2()<br>
    RuntimeError: maximum recursion depth exceeded</p>
  </blockquote>
  
  <p>My code is the following:</p>
  
  <pre><code>#!/usr/bin/python
  
  class Component:
      def print2(self):
          pass
  
  class Composite(Component):
      items = []
      name = 'composite'
  
      def __init__(self, name):
          self.name = name
  
      def add(self, item):
          self.items.append(item)
  
      def print2(self):
          if self.items:
              for item in self.items:
                  item.print2()
          else:
              print self.name
  
  class Leaf(Component):
      name = 'leaf'
  
      def __init__(self, name):
          self.name = name
  
      def print2(self):
          print self.name
  
  category = Composite('category1')
  leaf = Composite('leaf1')
  category.add(leaf)
  leaf = Leaf('leaf2')
  category.add(leaf)
  
  category.print2()
  </code></pre>
  
  <p>When I add <code>self.items = []</code> in the constructor ( <code>__init__</code> ), it works fine. Could you explain the behavior?</p>