title: call a method of class instance located inside a python list
body: <p>I have following classes in python:</p>
  
  <ul>
  <li><code>QueryElement</code> as a root class</li>
  <li><code>ElemMatch</code> and <code>GT</code> which inherit from the root.</li>
  </ul>
  
  <p>I have a list in <code>ElemMatch</code> class which is supposed to have instances of <code>QueryElement</code>.</p>
  
  <p>My problem is in invoking a method called <code>compute</code> from the instances inside the list, in <code>ElemMatch</code> class(compute method). The type of object inside the list is not identified by Python, and I do not know how to assign a type to the list. I do not have such a problem in Java since I could 'cast' to a type I like, but here I do not know how to solve it.</p>
  
  <p>I appreciate if you could help.</p>
  
  <pre><code>class QueryElement(object):
      __metaclass__ = abc.ABCMeta
  
      @abc.abstractmethod
      def addQueryElement(self, queryElement):        
          raise NotImplementedError( "Should have implemented this" )
  
  
      @abc.abstractmethod
      def compute(self):      
          raise NotImplementedError( "Should have implemented this" )
  
  
  class ElemMatch(QueryElement):
  
      def __init__(self):
          self._queryElements = []
  
      def addQueryElement(self, queryElement):
          self._queryElements.append(queryElement)
  
      def compute(self):
          elemMatch = {}
          if len (self._queryElements) &gt; 0:
              elemMatch['e'] = self._queryElements[0].compute()
  
          return elemMatch    
  
  
  class GT(QueryElement):
  
      def __init__(self):
          print 'someThing'
  
      def addQueryElement(self, queryElement):
          return None
  
      def compute(self):
          print 'compute GT!' 
  
  class PALLAS(object):
      def foo(self):
          gt = GT()
          elemMatch = ElemMatch()
  
          elemMatch.addQueryElement(gt)
          elemMatch.compute()
  
  p = PALLAS()
  p.foo()
  </code></pre>