title: python recursive iteration derivative polynomial function
body: <p>I am trying to write a class that initialises certain parameters that are to be use over again in different methods. However when I write a simple recursive algorithm based on initialised values I always get an error message and I really don't know how to solve it myself. </p>
  
  <p>Here is what the algorithm should look like:</p>
  
  <pre><code>def normal_recursion(poly):
  
      if len(poly) == 1:
          return poly[0]
  
      else:
          return poly[0] + normal_recursion(poly[1:])
  
  &gt;&gt;&gt; print(normal_recursion([1,2,3]))
  &gt;&gt;&gt; 6
  </code></pre>
  
  <p>which is exactly what should come out.</p>
  
  <p>Now my class looks like:</p>
  
  <pre><code>class Ps2(object):
  
      def __init__(self, poly):
          self.poly = poly
  
  
      def testFunction(self):
  
          '''Computes the sum of the elements of an indexable object.'''
  
          if len(self.poly) == 1:
              return self.poly[0]
  
          else:
              return self.poly[0] + self.testFunction(self.poly[1:])
  </code></pre>
  
  <p>if: </p>
  
  <pre><code>test = Ps2([1,2,3])
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>test.testFunction()
  </code></pre>
  
  <p>then:</p>
  
  <pre><code>TypeError: testFunction() takes 1 positional argument but 2 were given
  </code></pre>
  
  <p>I have tried all kinds of variations of 'def testFunction(self):' like 'def testFunction(self, self.poly)' but non of them were successful.</p>
  
  <p>However, there is a related question here on Stackoverflow: <a href="https://stackoverflow.com/questions/17843785/python-recursion-within-class">Python Recursion within Class</a> and I should mention that this algorithm  works.  </p>
  
  <p>The difference to my problem is that I want to used the values from def <strong>init</strong>(): as the input for my method. </p>
  
  <p>Anyway, your help is really being appreciated.</p>