title: How do I best reference a generator function in the parent class?
body: <p>I have a class hierarchy and in the parent class, I have a generator function which I sometimes need to use as is.  In the derived class, I have a preferred generator.  If I use  <code>super()</code> to assign the parent generator function to a variable (that is, a pointer to function), I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "foo.py", line 22, in &lt;module&gt;
      for i in baz.generator():
    File "foo.py", line 11, in generator
      for i in self.f():
  AttributeError: 'bar' object has no attribute 'f'
  </code></pre>
  
  <p>The following code works, but it uses the parent class name (<code>foo</code>) directly.  My question relates to the method <code>bar.generator</code>:  Is there a reasonable way of writing this to avoid directly referencing classes <code>bar</code> and <code>foo</code>?  The other two generators should not be touched.</p>
  
  <pre><code>class foo(object):    # base
      def generator(self):
          for i in range(10):
              yield i
  
  class bar(foo):       # derived
      def generator(self, override=True):
          f = bar.generator2 if override else foo.generator
          for i in f(self):
              yield i
  
      def generator2(self):
          for i in range(10):
              yield 2*i
  
  baz = bar()
  L = []
  for i in baz.generator():   # use baz.generator2
      L.append(i)
  print(L)
  L = []                      # use foo.generator
  for i in baz.generator(override=False):
      L.append(i)
  print(L)
  </code></pre>