[Zope] references to zope objects

Max M maxm@mxm.dk
Tue, 27 Aug 2002 13:53:26 +0200


Mario Bianchi wrote:

> I need (from within python code of an object of mine, call it 
> myObject) to find another existing zope object (call it targetObject) 
> and retain a reference to it, in order to call its API.


Currently the only absolute object id, is the objects path. Which you 
can get as:

    theObjectPath = object.getPhysicalPath()[1:], '/'

If you then want to get the object you can use:

    obj = self.getPhysicalRoot().restrictedTraverse(theObjectPath)

> As far as I have understood, objects in zope are identified by their 
> id attribute, so this attribute could, I guess, be used to reference 
> objects from python code of other objects. Am I wrong? 


In fact they are identified by their full path.

You could also check out the "mxmRelations" product which will do a lot 
of the grunt work for you:

    http://www.zope.org/Members/maxm/productList/mxmRelations


regards Max M

    "klaatu verata niktu"