autoadd class properties

M

manstey

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?
 
G

Gabriel Genellina

Is this clear?

I'm sorry, not for me. Some code showing how things are used now and
how you would like it to be, would help.


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 
G

George Sakkis

manstey said:
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
 
M

manstey

We've looked at them a little. Cache is a native OO dbase, so there is
no ORM required. Cache does that for you behind the scenes if you need
it to. What I want is to translate Cache classes and properties into
Python classes and properties. We can only use class wrappers, because
cache uses old style python objects, but this still works.

Because I am not an experienced programmer, the problem I face is how
to load ANY Cache class, whose properties the wrapper doesn't know in
advance, and turn the class properties into python properties.

So in Cache, I might have Name = String, Age = Integer, Colours = List,
in the class Person. The python binding provided by Cache creates a
Person class in Python, but it provides none of its properties, so I
want to write a wrapping class that adds the properties. Can you advise
me on how to do this?
 
M

manstey

Hi,

Cache is a pure OO dbase, so no ORM is required. Cache provides a
python equivalent for the Cache class, but not for the Cache
properties. Instead, the programmer has to know in advance the
properties and their type to get and set them. I want to wrap the
Python-cache class and add the Cache properties into the class, but I
don't know how to do this. Any ideas?



George said:
manstey said:
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
 
G

George Sakkis

manstey said:
We've looked at them a little. Cache is a native OO dbase, so there is
no ORM required. Cache does that for you behind the scenes if you need
it to. What I want is to translate Cache classes and properties into
Python classes and properties. We can only use class wrappers, because
cache uses old style python objects, but this still works.

Because I am not an experienced programmer, the problem I face is how
to load ANY Cache class, whose properties the wrapper doesn't know in
advance, and turn the class properties into python properties.

So in Cache, I might have Name = String, Age = Integer, Colours = List,
in the class Person. The python binding provided by Cache creates a
Person class in Python, but it provides none of its properties, so I
want to write a wrapping class that adds the properties. Can you advise
me on how to do this?

I'm afraid not, at least not without seeing an example. By the way,
I've never heard of Cache before and its name is too generic for
looking it up online; you should at least provide a link if you're
asking for help about obscure packages.

George
 
G

Gabriel Genellina

We've looked at them a little. Cache is a native OO dbase, so there is
no ORM required. Cache does that for you behind the scenes if you need
it to. What I want is to translate Cache classes and properties into
Python classes and properties. We can only use class wrappers, because
cache uses old style python objects, but this still works.

Because I am not an experienced programmer, the problem I face is how
to load ANY Cache class, whose properties the wrapper doesn't know in
advance, and turn the class properties into python properties.

So in Cache, I might have Name = String, Age = Integer, Colours = List,
in the class Person. The python binding provided by Cache creates a
Person class in Python, but it provides none of its properties, so I
want to write a wrapping class that adds the properties. Can you advise
me on how to do this?

Still unclear... Don't you have a way to iterate over all the
properties? Have you tried using dir() on the generated class?
BTW, do you know ZODB? It's an OO database written in Python and mostly
transparent for the user. You just write and use your objects as always
and the persistence mechanism does the rest.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top