Python 2.2 / Properties

Nikolai Kirsebom nikolai.kirsebom at siemens.no
Thu Jan 3 08:48:10 EST 2002


I have not downloaded the new version yet - but will do so in the new
future.

One question relating to the Properties.

I'm currently developping a small "inspector" where I from a Python
program will be able to read/write attributes of C++ objects in
another process (where Python is not possible to integrate).  I'll
also be able to execute some methods.  Anyhow, system is based on
useing socket for communication and the protocol is very simple.  Text
string consisting of object name and attribute name separated by '.'.
As an example:

cmd="Object.Attr1"
will send the command to read Attr1 of the object named "Object".

cmd="Object.Attr2=345"
will send the command to set Attr2 to the value 345 of the same
object.

(I'm using bison/flex to parse the commands).

Now to the question:  I would like to use the same property-get and
property-set methods (functions) for the remote attributes (as seen
from Python).  The example code below illustrates this.

--------------------------
class RemoteObj(object):
    name = "abc"
    def remPropGet(self, x):
        # Send command to remote object to set attribute value
        resp = Cmd.Send("%s.%s" % (name, NAME_OF_THIS_PROPERTY(x)))
        if resp['Status'] == OK:
            return resp['Result']
        return resp['Default']
        
    def remPropSet(self, newVal):
        resp = Cmd.Send("%s.%s=%s" % (name, NAME_OF_THIS_PROPERTY(x),
str(newVal)))

    RecordId = property(remPropGet, None, None, "RecordId")
    ItemNbr = property(remPropGet, remPropSet, None, "ItemNbr")
--------------------------

But is it possible in the methods to find out the name of the property
being 'handled' - or maybe I somehow could get to the doc-string for
the property.

Thanks for any hints/help.

Nikolai Kirsebom





More information about the Python-list mailing list