autoadd class properties

Discussion in 'Python' started by manstey, Dec 8, 2006.

  1. manstey

    manstey Guest

    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?
     
    manstey, Dec 8, 2006
    #1
    1. Advertisements

  2. At Friday 8/12/2006 05:38, manstey wrote:

    >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
     
    Gabriel Genellina, Dec 8, 2006
    #2
    1. Advertisements

  3. 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
     
    George Sakkis, Dec 8, 2006
    #3
  4. manstey

    manstey Guest

    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?
     
    manstey, Dec 8, 2006
    #4
  5. manstey

    manstey Guest

    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 Sakkis wrote:
    > 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
     
    manstey, Dec 9, 2006
    #5
  6. manstey wrote:

    > 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
     
    George Sakkis, Dec 9, 2006
    #6
  7. On 8 dic, 20:59, "manstey" <> wrote:
    > 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.

    --
    Gabriel Genellina
     
    Gabriel Genellina, Dec 9, 2006
    #7
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski
    Replies:
    0
    Views:
    1,019
    Nathan Sokalski
    Oct 17, 2005
  2. =?Utf-8?B?Q2hyaXN0b3BoZSBQZWlsbGV0?=

    CompositeControls: ViewState properties w/ Mapped properties probl

    =?Utf-8?B?Q2hyaXN0b3BoZSBQZWlsbGV0?=, Jan 19, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,211
    Steven Cheng[MSFT]
    Jan 19, 2006
  3. Kent Lichty
    Replies:
    0
    Views:
    886
    Kent Lichty
    Apr 16, 2004
  4. E11
    Replies:
    1
    Views:
    5,150
    Thomas Weidenfeller
    Oct 12, 2005
  5. SuperZE
    Replies:
    5
    Views:
    386
    SuperZE
    Oct 6, 2008
Loading...

Share This Page