On Feb 12, 5:15 am, Ben C <[EMAIL PROTECTED]> wrote:
> I think this works OK, but it seems a bit odd. Is there something more
> "Pythonic" I should be doing?

I have a similar tree to the one you describe here at work. I have a
visit function that is very similar to yours, but takes function
arguments for doing pre- and/or post- order operations on the node
(code below). It also yeilds the nodes, but in a postorder manner. The
flexibility is quite useful.

Regards,
Erich

    def visit(self,prefunc = None, postfunc = None):
        if prefunc:
            prefunc(self)

        for child in self.children:
            for y in child.visit(prefunc, postfunc):
                yield y

        if postfunc:
            postfunc(self)

        yield self
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to