MixIn method to call the method it overrides: how?
I have a MixIn class which defines a method foo(), and is then mixed in
with another class by being prepended to that class's __bases__ member,
thus overriding that class's definition of foo(). In my application
though it is necessary for the MixIn's foo() to call the overridden
foo(). How can I do this?
My current hack is to do this:
def foo(): # MixIn's method
orig_bases = self.__class__.__bases__
bases = list(orig_bases)
self.__class__.__bases__ = tuple(bases)
foo_orig = self.foo
self.__class__.__bases__ = orig_bases
# other stuff here...
Is there a better way? Does the above even work as I think it does?
Re: MixIn method to call the method it overrides: how?
Something like this will do what you want to achieve. I think the above
does as well what you want, but to me my solution is much more clear
print 'Base foo'
print 'Derived foo'
d = Derived()
|All times are GMT. The time now is 11:19 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.