title: Recursion in instance method in python
body: <p>I am trying to define a recursive method to walk all the nodes of a tree. I defined the Tree as the following:</p>
  
  <pre><code>class Tree(object):
  
      def __init__(self, value, lson=None, sibling=None):
          self.value = value
          if lson:
              self.lson = Tree(lson)
          else: 
              self.lson = None
  
          if sibling:
              self.sibling = Tree(sibling)
          else:
              self.sibling = None
  
      def __str__(self):
          return str(self.value) 
  </code></pre>
  
  <p>I have the following function that works:</p>
  
  <pre><code>def walk_tree(t):
      # walk in order
      print t
      if t.lson:
          walk_tree(t.lson)
      if t.sibling:
          walk_tree(t.sibling)
      return t
  </code></pre>
  
  <p>How do I turn this to an instance method?</p>
  
  <pre><code>def walk_tree(self):
      # walk in order
      print self.value
      if self.lson:
          self.walk_tree(self.lson)
      if self.sibling:
          self.walk_tree(self.sibling)
      return self
  </code></pre>
  
  <p>This will result in <code>Max recursion depth error...</code></p>
  
  <p>a. Is this how do you implement a recursive method?<br>
   b. Is there a justification here to use <code>yield</code>?<br>
   c. Is there a justification here to use <code>@staticmethod</code> which recieves a <code>Tree</code> instance?        </p>