Hi, I'm looking for a method to do the following thing: I have a variable called path with content '/test/abc/defg'. If I want to call the object behind this path from an object in an other path which can't acquire the Folder abc or abject defg, which is the function looking for ? my object is in path /test/xyz/ and has id t and is a PythonScript def t (self, path): # path is /test/abc/defg or ['test','abc','defg'] how to get the object behind the path ? Thanks Dirks
Not sure if I understood your question correctly but here's how to get an object from a path splitted = '/folder/subfolder/obj'.split('/') object = context # or 'self' if this is an external method for id in splitted: object = getattr(object, id) return object # should return the 'obj' object Maybe there are fancier methods to do this all in one go with some zope builtin method. Peter On Friday 28 December 2001 16:21, Dirk Datzert wrote:
Hi,
I'm looking for a method to do the following thing:
I have a variable called path with content '/test/abc/defg'. If I want to call the object behind this path from an object in an other path which can't acquire the Folder abc or abject defg, which is the function looking for ?
my object is in path /test/xyz/ and has id t and is a PythonScript
def t (self, path): # path is /test/abc/defg or ['test','abc','defg']
how to get the object behind the path ?
Thanks Dirks
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
You can call the restrictedTraverse method on your object. It accepts both forms of path you mentioned. '/test/abc/defg' or ['test','abc','defg'] So: def t(self, path): return self.restrictedTraverse(path) should do what you need without any problem. Em Friday 28 December 2001 15:47, Peter Bengtsson escreveu:
splitted = '/folder/subfolder/obj'.split('/') object = context # or 'self' if this is an external method for id in splitted: object = getattr(object, id)
return object # should return the 'obj' object
-- Sidnei da Silva X3ng Consultoria e Desenvolvimento Ltda. sidnei@x3ng.com.br
Thanks to all, that was I was looking for. Regards, Dirk Sidnei da Silva schrieb:
You can call the restrictedTraverse method on your object. It accepts both forms of path you mentioned. '/test/abc/defg' or ['test','abc','defg']
So:
def t(self, path): return self.restrictedTraverse(path)
should do what you need without any problem.
Em Friday 28 December 2001 15:47, Peter Bengtsson escreveu:
splitted = '/folder/subfolder/obj'.split('/') object = context # or 'self' if this is an external method for id in splitted: object = getattr(object, id)
return object # should return the 'obj' object
-- Sidnei da Silva X3ng Consultoria e Desenvolvimento Ltda. sidnei@x3ng.com.br
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Dirk Datzert writes:
... I have a variable called path with content '/test/abc/defg'. If I want to call the object behind this path from an object
"restrictedTraverse" see the Zope embedded help system --> API Reference, ObjectManagerItem Dieter
participants (4)
-
Dieter Maurer -
Dirk Datzert -
Peter Bengtsson -
Sidnei da Silva