Deciding inheritance at instantiation?

Tobiah toby at tobiah.org
Mon Aug 6 13:42:09 EDT 2012


On 08/03/2012 02:55 PM, Terry Reedy wrote:
> 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.
>

Very cool.  Just what I was after.  Thanks.

Tobiah



More information about the Python-list mailing list