An attempt to use a python-based mini declarative language for formdefinition

Carlos Ribeiro carribeiro at
Wed Sep 22 22:01:42 CEST 2004

On Wed, 22 Sep 2004 13:10:00 -0500, Larry Bates <lbates at> wrote:
> You may can write your own __setattr__ method.
> That way you can keep track of the order of
> the fields yourself.


I may have made a mistake on my own code, but __setattr__ would not
work for me; I'm creating my instances through a metaclass, and I'm
using class attributes for the fields.

In your example the form fields are instance attributes. In this case,
I agree it works. But as I said -- I was testing if I could make it
work using class attributes and metaclasses. I think that the
resulting code is much cleaner (after all black magic is done and
hidden from the user, that is). Compare:

1) using class attributes

class UserForm(Form):
   nickname = TextBox(length=15, default="")
   password = TextBox(length=10, default="", password=True)
   name     = TextBox(length=40, default="")

2) using instance atttributes

class UserForm(Form):
   def __init__(self):
       self.nickname = TextBox(length=15, default=""))
       self.password = TextBox(length=10, default="", password=True))     = TextBox(length=40, default="")

Others may think that's a small difference, but if I could choose
between both approaches, I would surely pick (1).

Carlos Ribeiro
Consultoria em Projetos
mail: carribeiro at
mail: carribeiro at

More information about the Python-list mailing list