autoadd class properties

George Sakkis george.sakkis at gmail.com
Fri Dec 8 04:18:22 EST 2006


manstey wrote:

> I have a ClassWrapper that wraps around a third party database object.
> Each database object has a set of properties, like columns in a
> relational database.
>
> I want my wrapper to generate a property for each database object and
> load its value into it.
>
> Thus, in my database (which is an oodbms) say I have a MyDbaseClass
> with MyProperty1, MyProperty2, etc, after it is loaded, I have:
>
> dbase_object = LoadMyDbaseClass
> PythonDbaseClass = PythonWrapper(dbase_object)
>
> I can then load in a list of ['MyProperty1','MyProperty2', etc].
>
> But how can I turn these list elements into PythonDbaseClass
> properties, so that I could then simply have:
>
> print PythonDbaseClass.MyProperty1
> PythonDbaseClass.MyProperty2="4"
>
> Is this clear?

Sounds as if you're reinventing a part of an ORM. Have you checked out
SQLAlchemy or Django's ORM, in case they provide what you want out of
the box ?

George




More information about the Python-list mailing list