determining the number of output arguments

Peter Otten __peter__ at web.de
Tue Nov 16 11:58:52 EST 2004


Jeremy Bowers wrote:

> the instances I do have is a tree iterator that on every "next()" returns
> a depth and the current node, because the code to track the depth based
> on the results of running the iterator is better kept in the iterator than
> in the many users of that iterator. But I don't like it; I'd rather make
> it a property of the iterator itself or something, but there isn't a
> code-smell-free way to do that, either, as the iterator is properly a
> method of a certain class, and trying to pull it out into its own class
> would entail lots of ugly accessing the inner details of another class.

You could yield Indent/Dedent (possibly the same class) instances whenever
the level changes - provided that the length of sequences of nodes with the
same depth does not approach one.

Peter



More information about the Python-list mailing list