title: Printing a Tree data structure in Python
body: <p>I was looking for a possible implementation of tree printing, which prints the tree in a user-friendly way, and not as an instance of object.</p>
  
  <p>I came across this solution on the net:</p>
  
  <p>source: <a href="http://cbio.ufs.ac.za/live_docs/nbn_tut/trees.html">http://cbio.ufs.ac.za/live_docs/nbn_tut/trees.html</a></p>
  
  <pre><code>class node(object):
      def __init__(self, value, children = []):
          self.value = value
          self.children = children
  
      def __repr__(self, level=0):
          ret = "\t"*level+repr(self.value)+"\n"
          for child in self.children:
              ret += child.__repr__(level+1)
          return ret
  </code></pre>
  
  <p>This code prints the tree in the following way:</p>
  
  <pre><code>'grandmother'
      'daughter'
          'granddaughter'
          'grandson'
      'son'
          'granddaughter'
          'grandson'
  </code></pre>
  
  <p>Is it possible to have the same result but without changing the <code>__repr__</code> method, because I am using it for another purpose.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Solution without modifying <code>__repr__</code> and <code>__str__</code></p>
  
  <pre><code>def other_name(self, level=0):
      print '\t' * level + repr(self.value)
      for child in self.children:
          child.other_name(level+1)
  </code></pre>