Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can just use the bound method object itself:</p> <pre><code>tasks = [a.request for a in self.types["social"]] # ^^^^^^^^^ grabbers = executeChainResults(tasks, [(query, 0)] * len(tasks)) # ^^^^^^^^^^^^^^^^^^^^^^^^^ </code></pre> <p>If you insist on calling your methods through the base class you could also do it like this:</p> <pre><code>from abc import ABCMeta from functools import wraps def virtualmethod(method): method.__isabstractmethod__ = True @wraps(method) def wrapper(self, *args, **kwargs): return getattr(self, method.__name__)(*args, **kwargs) return wrapper class IBase(object): __metaclass__ = ABCMeta @virtualmethod def my_method(self, x, y): pass class AddImpl(IBase): def my_method(self, x, y): return x + y class MulImpl(IBase): def my_method(self, x, y): return x * y items = [AddImpl(), MulImpl()] for each in items: print IBase.my_method(each, 3, 4) b = IBase() # &lt;-- crash </code></pre> <p>Result:</p> <pre><code>7 12 Traceback (most recent call last): File "testvirtual.py", line 30, in &lt;module&gt; b = IBase() TypeError: Can't instantiate abstract class IBase with abstract methods my_method </code></pre> <p>Python doesn't support interfaces as e.g. Java does. But with the <code>abc</code> module you can ensure that certain methods must be implemented in subclasses. Normally you would do this with the <code>abc.abstractmethod()</code> decorator, but you still could not call the subclasses method through the base class, like you intend. I had a similar question once and I had the idea of the <code>virtualmethod()</code> decorator. It's quite simple. It essentially does the same thing as <code>abc.abstratmethod()</code>, but also redirects the call to the subclasses method. The specifics of the <code>abc</code> module can be found in <a href="http://docs.python.org/library/abc.html" rel="nofollow">the docs</a> and in <a href="http://www.python.org/dev/peps/pep-3119/" rel="nofollow">PEP3119</a>.</p> <p>BTW: I assume you're using Python >= 2.6.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload