Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

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

@DKAMX

Description

@DKAMX

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions