[Zope] way the acquired a path

Peter Bengtsson mail@peterbe.com
Fri, 28 Dec 2001 18:47:09 +0100


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 )