[Zope] Re: tree traversal question

Evan Simpson evan@4-am.com
Thu, 05 Jun 2003 13:48:11 -0500


Ruslan Spivak wrote:
> Does any body have simple solution (python script) for tree 
> traversal(not recursive), so that i can traverse objects level by level 
> from root to bottom?

Memory intensive:

root = container.restrictedTraverse('/')
for path, ob in root.ZopeFind(root, search_sub=1):
     # do something

Requires two Scripts:

root = container.restrictedTraverse('/')
f = context.myScriptThatDoesSomething
root.ZopeFindAndApply(root, search_sub=1, apply_func=f)

Recurses once:

##parameters:ob=None,path=None
if path is None:
     root = container.restrictedTraverse('/')
     root.ZopeFindAndApply(root, search_sub=1, apply_func=script)
else:
     # do something

Cheers,

Evan @ 4-am