Create classes at runtnime

Marc Aymerich glicerinu at
Sat Feb 5 13:06:41 CET 2011

Thank you all for the answers!

I'll try to give you the context in which I need to generate classes
like this.

I'm developing a reusable control panel for an ISP. I have several
modules (VirtualUser, SystemUser, VPS, VirtualHost, ...) and they all
share the fact that you can have limits on resource consumption. for

VPS: has limits on swap, memory, cpu and disk.
SystemUser: has limits on disk and traffic.

As all modules share this property of being limited I have decided to
split the limit functionality in a separate module (called resources).
Resources are associated dinamically with (vps, systemuser ...)
through a Monitor class. So it's up to you decide what limits you are
interested to put in the VPS or in the SystemUser ...

So when you attach the "disk limit" to SystemUser model is necessary
to create a web form for SystemUser a bit different than if you decide
to have disk and traffic limits. That is what my posted code is
supposed to do.

Do you think that I am on the wrong way designing the control panel
like this?

Btw, I've seen several interesting ideas to create the class
dinamically (with class factorys, MetaClass, dictionaries ..), but I
have not yet clear whether this will be usefull for create the
__init__ function at runtime too. Any clue on this?

Many, many thanks!! :)

More information about the Python-list mailing list