Currently, it seems there is no way to "capture" the output of the rendered tree, to make it available for later use (as opposed to immediately printing it).
My current workaround for this involves hooking sys.stdout, which isn't ideal but works:
try:
buf = io.StringIO()
stdout = sys.stdout
sys.stdout = buf
pptree.print_tree(tree)
finally:
sys.stdout = stdout
buf.seek(0)
render = buf.read()
It would be nice if there was a version that just returned the string. You can then refactor the code of print_tree to just print the output of this operation.
Currently, it seems there is no way to "capture" the output of the rendered tree, to make it available for later use (as opposed to immediately printing it).
My current workaround for this involves hooking
sys.stdout, which isn't ideal but works:It would be nice if there was a version that just returned the string. You can then refactor the code of
print_treeto just print the output of this operation.