Open leonardbinet opened 4 years ago
In my use case, here is why it is painful. I have a class, let's call it NiceReprTree
inheriting from treelib.tree.Tree
, for which I want the repr
to be the name of the class followed by the output of show
method. The problem here with this print
is that my stdout
will be spammed..
Example:
class NiceReprTree(Tree):
def __str__(self):
return '<{class_}>\n{tree}'.format(
class_=text(self.__class__.__name__),
tree=text(self.show())
)
def __repr__(self):
return self.__str__()
Did you see that you can use t = tree.show(stdout=False)
?
I feel like this issue is already fixed on the master at least.
IMO it would make more sense that the
show
method returnsself._reader
value, and that user then choose what to do with it (ie print to stdout, write in a file, store somewhere etc)https://timber.io/blog/the-pythonic-guide-to-logging/