title: Printing a numbered outline of a hierarchical tree
body: <p>I'm trying to write a function that prints a object hierarchy tree (in Blender 3D but this is a general Python question) with decimal outline numbering.</p>
  
  <p>I require:</p>
  
  <ul>
  <li>an optional indent with any symbol like <code>"+"</code> or <code>"--"</code> or no indent <code>""</code>, and </li>
  <li>an optionally appended <code>".0"</code> to nodes that have children to distinguish branches from leaves.</li>
  </ul>
  
  <p>For example, in Blender I created an armature with bones and hierarchy is like this:</p>
  
  <pre><code>+ Life
  ++ Bacteria
  ++ Eukaryota
  +++ plants
  +++ animals
  ++++ Vertebrates
  +++++ amphibians
  +++++ reptiles
  +++++ mammals
  </code></pre>
  
  <p>In de Text Editor I created this basic script:  </p>
  
  <pre><code>import bpy
  D = bpy.data
  root = D.armatures['Armature'].bones['Life']
  
  def print_hierarchy(obj, indent = "+"):
      print(indent, obj.name)
      for child in obj.children:
          print_hierarchy(child, indent+"+")
  print_hierarchy(root)
  </code></pre>
  
  <p>this script outputs:</p>
  
  <pre><code>+ Life
  ++ Bacteria
  ++ Eukaryota
  +++ plants
  +++ animals
  ++++ Vertebrates
  +++++ amphibians
  +++++ reptiles
  +++++ mammals
  </code></pre>
  
  <p>I want it to look like this</p>
  
  <pre><code>1.0 Life
      1.1 Bacteria
      1.2.0 Eukaryota
          1.2.1 plants
          1.2.2.0 animals
              1.2.2.1.0 Vertebrates
                  1.2.2.1.1 amphibians
                  1.2.2.1.2 reptiles
                  1.2.2.1.3 mammals
  </code></pre>
  
  <p>I've tinkered with the (recursive) function <code>print_hierarchy()</code> but it breaks everytime I try to add something new to it. I can't wrap my brain around it so I'd like some help please.</p>
  
  <p>Is a while-loop better / more efficient / faster than a recursive function for this sort of thing?</p>