On Oct 31, 9:57 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Wed, 31 Oct 2007 00:36:34 -0300, Anand <[EMAIL PROTECTED]> escribió: > > >> No, that is an argument for multiple-inheritance, mixin classes etc. You > >> know when constructing the object what behaviour you want it to have. It > >> isn't an argument for changing the behaviour of an existing object > >> dynamically. > > Partially true. I don't want to change the behavior of an exiting > > object. I know what behavior I want to have at the time of creating. > > This can be achieved by creating classes dynamically by parameterizing > > the base class, which I thought is ugly. > > If you know at compile time which features you want, you can use multiple > inheritance to define the new class. > If you only know the set of clases to mix at run time, you can dinamically > create new classes with 'type': > > newclass = type('newclass', (CachedDB, SimpleDB), {}) > db = newclass() > db.withIDs will call CachedDB.withID, as you want.
Interesting. CachedDB.withID should call withID from its super class (here SimpleDB), when it is not in cache. How to do that?
-- http://mail.python.org/mailman/listinfo/python-list