Module mixins allow you to inherit from modules. This is how ruby achieves multiple inheritance, and I just wanted to show it's possible in python as well.
1 2 | def mixin(mod):
return type("mixin(%s)" % (mod.__name__,), (object,), mod.__dict__)
|
see http://sebulba.wikispaces.com/recipe+module+mixins for more info and examples.
Tags: extending
Cool. What about accessing 'self'?
Okay, saw it in the wiki page.
Maybe the mixin function can do the include too, so this:
import testmixin
class Bar(mixin(testmixin)):
Can be replaced with this:
class Bar(mixin("testmixin")):