Deciding inheritance at instantiation?

Terry Reedy tjreedy at udel.edu
Fri Aug 3 17:55:33 EDT 2012


On 8/3/2012 4:48 PM, Tobiah wrote:
> I have a bunch of classes from another library (the html helpers
> from web2py).  There are certain methods that I'd like to add to
> every one of them.  So I'd like to put those methods in a class,
> and pass the parent at the time of instantiation.  Web2py has
> a FORM class for instance.  I'd like to go:
>
>      my_element = html_factory(FORM)
>
> Then my_element would be an instance of my class, and also
> a child of FORM.
>
> I started messing with decorators, but it became difficult
> for me to visualise how to do this.

Use type(name, bases, content) for dynamic class creation.

-- 
Terry Jan Reedy




More information about the Python-list mailing list