title: Python class 2.7 binary tree
body: <p>Here is the Class named BNode,</p>
  
  <pre><code>class BNode:
      def __init__(self, value=None, left=None, right=None):
          self.value = value
          self.left = left
          self.right = right
      def __repr__(self):
          return '' % (self.value, self.left, self.right)
  </code></pre>
  
  <p>and print out below</p>
  
  <pre><code>&gt;&gt;&gt; root = BNode('root')
  &gt;&gt;&gt; root.left = BNode('left') 
  &gt;&gt;&gt; root.right = BNode('right')
  &gt;&gt;&gt; root.left.left = BNode('left-left')
  &gt;&gt;&gt; root.left.right = BNode('left=right')
  
  &gt;&gt;&gt; print root
  
  root (
  left (
  left-left (
  None
  None)
  left-right (
  None
  None))
  right (
  None
  None))
  </code></pre>
  
  <p>Q) Modify the Class, so that the result like below could be made.</p>
  
  <pre><code>root (
      left (
          left-left (
              None
              None)
          left-right (
              None
              None))
      right (
          None
          None))
  </code></pre>
  
  <hr>
  
  <p>and my answer is the following one.</p>
  
  <pre><code>class BNode:
      def __init__(self, value=None, left=None, right=None):
          self.value = value
          self.left = left
          self.right = right
      def __repr__(self, level=0):
          R = ''
          for ele in range(level):
              R += '\t'
          R += str(self.value)
          R += ' ('
          R += '\n'
          if isinstance(self.left, BNode):
              R += BNode.__repr__(self.left, level+1)
          else:
              for ele in range(level+1):
                  R += '\t'
              R += str(self.left)
          R += '\n'
          if isinstance(self.right, BNode):
              R += BNode.__repr__(self.right, level+1)
          else:
              for ele in range(level+1):
                  R += '\t'
              R += str(self.right)
          R += ')'
          return R
  </code></pre>
  
  <p>But I want to know if it is the best solution for this question. 
  I think there is much nicer one...
  Is there some efficient way? </p>
  
  <p>Thanks in advance ~ :)</p>