[Tutor] Tree again: iterator, yield, increase (treelib)

Alan Gauld 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 [2] 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 [1]
> 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?


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list