On 11/16/05, Ian Bicking <[EMAIL PROTECTED]> wrote:
> I'd played around unsuccessfully with weird dual object/class objects,
> but I never quite figured it out.  But I must know more now, because it
> wasn't too hard.  Here's an example with a very brief test:
>
>    http://svn.colorstudy.com/home/ianb/subclass_instance/
>
> Basically this:
>
>    class MyForm(TableForm):
>        foo1 = TextField()
>        foo2 = TextField()
>
> Is exactly equivalent to:
>
>    MyForm = type(TableForm)('MyForm', (TableForm,), {'foo1':
> TextField(), 'foo2': TextField})
>
> So if TableForm is an instance, then type(TableForm) is the class, and
> the class is called with those arguments (i.e., instantiating).
>
> It's all a little wacky, so I don't know that I'd recommend the trick.
> But it does make large keyword-based instanciation easier on the eye.

Interesting. I'll have to play around with this a bit to see what I
can do. I don't mind a little bit of wackiness in the TurboGears code
if it makes the application code nicer. (A *little* mind you... I'd
hate for TG to become so complex inside that no one else could work on
it!)

Kevin

Reply via email to