-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #139: replace stdout
with end
in show
.
#140
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -780,7 +780,8 @@ def _write_line(line, f): | |
key, reverse, line_type, data_property, func=handler) | ||
|
||
def show(self, nid=None, level=ROOT, idhidden=True, filter=None, | ||
key=None, reverse=False, line_type='ascii-ex', data_property=None, stdout=True): | ||
key=None, reverse=False, line_type='ascii-ex', data_property=None, | ||
end='\n\n'): | ||
""" | ||
Print the tree structure in hierarchy style. | ||
|
||
|
@@ -801,23 +802,23 @@ def show(self, nid=None, level=ROOT, idhidden=True, filter=None, | |
:param reverse: the ``reverse`` param for sorting :class:`Node` objects in the same level. | ||
:param line_type: | ||
:param data_property: the property on the node data object to be printed. | ||
:param end: the string to append to the final line of the output. By | ||
default, an extra newline is printed; pass '\n' if this is not | ||
desired. | ||
:return: None | ||
""" | ||
self._reader = "" | ||
self._reader = [] | ||
|
||
def write(line): | ||
self._reader += line.decode('utf-8') + "\n" | ||
self._reader.append(line.decode('utf-8')) | ||
|
||
try: | ||
self.__print_backend(nid, level, idhidden, filter, | ||
key, reverse, line_type, data_property, func=write) | ||
except NodeIDAbsentError: | ||
print('Tree is empty') | ||
|
||
if stdout: | ||
print(self._reader) | ||
else: | ||
return self._reader | ||
print('\n'.join(self._reader), end=end) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I strongly disagree with using Using
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This article talk about logging. I don't think It is related to this use case here. Here it is just an helper function. You could create 2 functions, it would make the API simpler. I also think a stream as input is better, anyway the default value is stdout. |
||
|
||
def siblings(self, nid): | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO there is no reason to have a member variable as @GalacticStarfish explains it in #91. What do you think of replacing
self._reader
by areader
variable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, that's just a wast of memory cause it is cached but not reused AFAICS.