Skip to content
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

Tree.show function with new parameters and improved behaviour #233

Open
DKAMX opened this issue Oct 7, 2024 · 0 comments
Open

Tree.show function with new parameters and improved behaviour #233

DKAMX opened this issue Oct 7, 2024 · 0 comments

Comments

@DKAMX
Copy link

DKAMX commented Oct 7, 2024

Hello, I have looked at the current implementation of Tree.show function in the master branch. I think the previous design is a bit confusing.

When stdout=True, I understand it to be using sys.stdout.buffer.write so I can directly write bytes to the console. However in tree.py line 932. It simply prints out the bytes with the print function. I don't understand why it was designed like that.

Refer to #215 , if the idea of stdout=True was to simply output to the console, then this is conflicting among users as I and this #230 have issues with encoding. I have to do print(tree.show(stdout=False) which makes stdout=True useless.

I suggest an improvement with the following:

if stdout:
    return self._reader.encode("utf-8")
else:
    return self._reader

Or add an encoding parameter to the show function, allowing use to choose #tree.show(encoding='utf-8') if we having trouble with the final print.

if stdout:
    if encoding is not None:
        print(self._reader.encode(encoding))
    else:
        print(self._reader)
else:
    return self._reader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant