autoadd class properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • manstey

    #1

    autoadd class properties

    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 = LoadMyDbaseClas s
    PythonDbaseClas s = PythonWrapper(d base_object)

    I can then load in a list of ['MyProperty1',' MyProperty2', etc].

    But how can I turn these list elements into PythonDbaseClas s
    properties, so that I could then simply have:

    print PythonDbaseClas s.MyProperty1
    PythonDbaseClas s.MyProperty2=" 4"

    Is this clear?

  • Gabriel Genellina

    #2
    Re: autoadd class properties

    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

    Comment

    • George Sakkis

      #3
      Re: autoadd class properties

      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 = LoadMyDbaseClas s
      PythonDbaseClas s = PythonWrapper(d base_object)
      >
      I can then load in a list of ['MyProperty1',' MyProperty2', etc].
      >
      But how can I turn these list elements into PythonDbaseClas s
      properties, so that I could then simply have:
      >
      print PythonDbaseClas s.MyProperty1
      PythonDbaseClas s.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

      Comment

      • manstey

        #4
        Re: autoadd class properties

        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?

        Comment

        • manstey

          #5
          Re: autoadd class properties

          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 = LoadMyDbaseClas s
          PythonDbaseClas s = PythonWrapper(d base_object)

          I can then load in a list of ['MyProperty1',' MyProperty2', etc].

          But how can I turn these list elements into PythonDbaseClas s
          properties, so that I could then simply have:

          print PythonDbaseClas s.MyProperty1
          PythonDbaseClas s.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

          Comment

          • George Sakkis

            #6
            Re: autoadd class properties

            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

            Comment

            • Gabriel Genellina

              #7
              Re: autoadd class properties



              On 8 dic, 20:59, "manstey" <mans...@csu.ed u.auwrote:
              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

              Comment

              Working...