By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,095 Members | 1,586 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,095 IT Pros & Developers. It's quick & easy.

MixIn method to call the method it overrides: how?

P: n/a
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.__class__.__bases__ = orig_bases

# other stuff here...
Is there a better way? Does the above even work as I think it does?

Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
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

class Base(object):
def foo(self):
print 'Base foo'

class Derived(Base):
def foo(self):
super(Derived, self).foo()
print 'Derived foo'
d = Derived()

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.