title: python iterator through tree with list of children
body: <p>i don't get the full grasp on python iterators,
  i got an object with a list of children, and i want to iterate through this structure.
  I want to  get the same behaviour as with the printall function but with an iterator.</p>
  
  <pre><code>    class t:
              def __init__(self, i):
                      self.l = []
                      self.a = 0
                      for ii in range(i):
                              self.a = ii
                              self.l.append(t(i-1))
  
              def __iter__(self):
                      return self
  
              def next(self):
                      for i in self.l:
                              yield i.__iter__()
                      yield self
  
              def printall(self):
                      for i in self.l:
                              i.printall()
                      print self.a
  </code></pre>
  
  <p>hope thats enough information, thanks</p>
  
  <p>edit:</p>
  
  <p>i just want to be able to iterate through all the leafs of the tree and do something with the object, i.e. when i have an instance</p>
  
  <pre><code>    bla = t(3) 
  </code></pre>
  
  <p>i want to be able to go through every node with </p>
  
  <pre><code>    for x in bla:
              print x.a
  </code></pre>
  
  <p>for example. i want to be able to something with each x, 
  i just have to access every child once</p>