caesar0301 / treelib

An efficient implementation of tree data structure in python 2/3.
http://treelib.readthedocs.io/en/latest/
Other
801 stars 185 forks source link

Not possible to direct output to an arbitrary io-stream. Can only print tree to file or stdout #95

Open GalacticStarfish opened 6 years ago

GalacticStarfish commented 6 years ago

The tree.show method has alot of options:

tree.show([nid[, level[, idhidden[, filter[, key[, reverse[, line_type[, data_property]]]]]]]]]

However, none of these parameters is an iostream.

Also, tree.save2file accepts a filename, but not a filestream. Meaning we cannot redirect the output to a stream other than a file.

Below is the full signature for , tree.save2file

tree.save2file(filename[, nid[, level[, idhidden[, filter[, key[, reverse]]]]]]])

It would be nice to be able to send a print-out of the tree to any stream we desire. For example,

import io with io.StringIO("") as str_strm: t.show(strem = str_strm)

import sys t.show(strm = sys.stderr)

I would think that there would be an optional iostream parameter to Tree.show and/or Tree.save2file with its default value being sys.stdout