[Tutor] Tree again: iterator, yield, increase (treelib)
alan.gauld at yahoo.co.uk
Sat Oct 14 19:30:42 EDT 2017
On 14/10/17 16:44, Chris wrote:
> I've a question about treelib library from pip.
The list focus is the language and standard library
so if you want to ask about other code you need to
give us more context. treelib is not a commonly
discussed module, in fact this the first mention I've seen.
> Treelib stores a tree and offers functions to add, delete or move
> nodes. Furthermore, you can print a tree like this:
> I'm trying to understand how the print function is working.
You need to show us some code. specifically the
functions that you mention below. Don't assume we
know them or that we will be downloading a random
module just to read it.
> 1. The documentation  says, you have to call tree.show() to print
> the tree above.
> 2. tree.show calls the self__print_backend(...)
> 3. It seems that nid is initialized in get_iter, Line 218 
> 4. nid is passed as parameter to __get_iter and the other
> participating funtions
> 5. the node with the id nid is fetched in line 222.
> 6. In Line 190 there's a loop.
> I don't understand what increments nid or what makes the __get_iter
> function loop through the self._nodes dictionary defined in Line 106?
Neither do I without seeing the code.
Although the classic approach to traversing trees is
to use recursion so, do any of the functions call themselves?
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor