Python: how to inherite and override
- by Guy
Consider this situation:
I get an object of type A which has the function f. I.e:
class A:
def f():
print 'in f'
def h():
print 'in h'
and I get an instance of this class but I want to override the f function but save the rest of the functionality of A. So what I was thinking was something of the sort:
class B(A):
....
def f():
print 'in B->f'
and the usage would be:
def main(a):
b = B(a)
b.f() #prints "in B->f"
b.h() #print "in h"
How do you do such a thing?