Hello, zope users. 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? Thanks in advance. Best regards, Ruslan
restrictedTraverse() ? -aj --On Donnerstag, 5. Juni 2003 15:45 Uhr +0300 Ruslan Spivak <alienoid@is.lg.ua> wrote:
Hello, zope users.
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?
Thanks in advance.
Best regards, Ruslan
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
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?
First, check ZopeLabs. (But I don't think they have that yet.) Else, find yourself an algorithm book (or a search engine!), and look for a breadth-first traversal/search algorithm. It probably won't have anything in Python, but it should have pseudo-code (which is close) or C (which is translatable). Then do it, it shouldn't be hard: the algorithm shouldn't be but ten lines or so, and the Zope methods for getting children and going to children are dead easy. Afterwards, submit your code to ZopeLabs as a recipe. Here's some places to start: http://www.google.com/search?hl=en&ie=ISO-8859-1&q=breadth-first+tree+traver... http://www.cs.bu.edu/teaching/c/tree/breadth-first/ http://www.ics.uci.edu/~eppstein/161/960215.html And what's wrong with recursion anyway? --jcc
J Cameron Cooper wrote at 2003-6-5 13:05 -0500:
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?
The tree support in the ZTUtils package (".../lib/python/ZTUtils") may contain what you look for. Someone else implemented alternative tree support, which should be simpler (he says). Check the archive of "zope-announce@zope.org". Dieter
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
participants (5)
-
Andreas Jung -
Dieter Maurer -
Evan Simpson -
J Cameron Cooper -
Ruslan Spivak