How to Adding Functionality to a Class by metaclass(not by inherit)
steven.bethard at gmail.com
Fri Aug 12 06:55:12 CEST 2005
kyo guan wrote:
> How to Adding Functionality to a Class by metaclass(not by inherit)
> class MetaFoo(type):
> def __init__(cls, name, bases, dic):
> super(MetaFoo, cls).__init__(name, bases, dic)
> for n, f in inspect.getmembers(Foo, inspect.ismethod):
> setattr(cls, n, f)
See if that works. I think it should.
But the real question is why you want to do this. Why can't you just
inherit from Foo?
More information about the Python-list