How to call a method from a class with inheritence on an object of the base class?
<p>I have two classes. One inherits the other:</p>

<pre><code>class A(object):
    def __init__(self):
        self.attribute = 1

class B(A):
    def get_attribute(self):
        return self.attribute
</code></pre>

<p>I would like to be able to call methods from B on objects of type A. I cannot edit class A (it is a built in class). When I try to call a method from B, there is an AttributeError. </p>

<pre><code>a = A()
a.get_attribute()

Traceback (most recent call last):
  File "&lt;pyshell#7&gt;", line 1, in &lt;module&gt;
    a.get_attribute()
AttributeError: 'A' object has no attribute 'get_attribute'
</code></pre>

<p>Is there a way to call methods from B without explicitly declaring the data to be of type B?</p>

<p>While it is discouraged to do you can use any method like a function. In your case it would be</p>

<pre><code>B.get_attribute(a)
</code></pre>

<p>Of cause the method has to be compatible with the type of <code>a</code>.</p>

python python-2.7