Re: Create classes at runtnime

2011-02-06 Thread Peter Otten
Marc Aymerich wrote: > On Feb 5, 1:06 pm, Marc Aymerich wrote: >> 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, V

Re: Create classes at runtnime

2011-02-05 Thread Miki Tebeka
> I need to create a pretty complex class at runtime. You can take the approach that namedtuple does and create a python code for the class as string and then exec it. See http://svn.python.org/view/python/trunk/Lib/collections.py?view=markup HTH, -- Miki http://pythonwise.blogspot.com -- http:

Re: Create classes at runtnime

2011-02-05 Thread Marc Aymerich
On Feb 5, 1:06 pm, Marc Aymerich wrote: > 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

Re: Create classes at runtnime

2011-02-05 Thread Peter Otten
Carl Banks wrote: > On Feb 4, 1:32 pm, Peter Otten <__pete...@web.de> wrote: >> Marc Aymerich wrote: >> > I need to create a pretty complex class at runtime. something like >> > this one: >> >> I have a hunch that you've never heard the famous Kernighan quote: >> >> "Everyone knows that debugging

Re: Create classes at runtnime

2011-02-05 Thread Marc Aymerich
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 resour

Re: Create classes at runtnime

2011-02-04 Thread Chris Rebert
On Fri, Feb 4, 2011 at 6:10 PM, Steven D'Aprano wrote: > On Fri, 04 Feb 2011 17:19:23 -0800, Ian wrote: >> On Feb 4, 5:49 pm, Steven D'Aprano > +comp.lang.pyt...@pearwood.info> wrote: >>> Just add in the class attributes you want after creating the class. > [...] >> This would probably cause some

Re: Create classes at runtnime

2011-02-04 Thread Steven D'Aprano
On Fri, 04 Feb 2011 17:19:23 -0800, Ian wrote: > On Feb 4, 5:49 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> Just add in the class attributes you want after creating the class. [...] > This would probably cause some problems with the Django metaclass. It > inspects the class di

Re: Create classes at runtnime

2011-02-04 Thread Ian
On Feb 4, 5:49 pm, Steven D'Aprano wrote: > Just add in the class attributes you want after creating the class. > > class VirtualUserLimitForm(ModelForm): >     pass > > f = forms.CharField  # alias for brevity > for name, value in [ >     ('swap_limit', f(max_length=100, initial=monitor1.default_

Re: Create classes at runtnime

2011-02-04 Thread Steven D'Aprano
On Fri, 04 Feb 2011 11:17:39 -0800, Marc Aymerich wrote: > Hi! > I need to create a pretty complex class at runtime. something like this > one: > > (note: "" means that the number of attributes can be variable) > > class VirtualUserLimitForm(ModelForm): > swap_limit = forms.CharField(max_

Re: Create classes at runtnime

2011-02-04 Thread Ian
On Feb 4, 2:32 pm, Peter Otten <__pete...@web.de> wrote: > > (note: "" means that the number of attributes can be variable) > > > class VirtualUserLimitForm(ModelForm): > >     swap_limit = forms.CharField(max_length=100, > > initial=monitor1.default_limit) > >     memory_limit = forms.CharFiel

Re: Create classes at runtnime

2011-02-04 Thread Carl Banks
On Feb 4, 11:17 am, Marc Aymerich wrote: > Hi! > I need to create a pretty complex class at runtime. something like > this one: > > (note: "" means that the number of attributes can be variable) > > class VirtualUserLimitForm(ModelForm): >     swap_limit = forms.CharField(max_length=100, > ini

Re: Create classes at runtnime

2011-02-04 Thread Carl Banks
On Feb 4, 1:32 pm, Peter Otten <__pete...@web.de> wrote: > Marc Aymerich wrote: > > I need to create a pretty complex class at runtime. something like > > this one: > > I have a hunch that you've never heard the famous Kernighan quote: > > "Everyone knows that debugging is twice as hard as writing

Re: Create classes at runtnime

2011-02-04 Thread Peter Otten
Marc Aymerich wrote: > I need to create a pretty complex class at runtime. something like > this one: I have a hunch that you've never heard the famous Kernighan quote: "Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be

Create classes at runtnime

2011-02-04 Thread Marc Aymerich
Hi! I need to create a pretty complex class at runtime. something like this one: (note: "" means that the number of attributes can be variable) class VirtualUserLimitForm(ModelForm): swap_limit = forms.CharField(max_length=100, initial=monitor1.default_limit) memory_limit = forms.Char