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

function display tree #2

Closed
dauptaia opened this issue Oct 15, 2020 · 4 comments · Fixed by #3
Closed

function display tree #2

dauptaia opened this issue Oct 15, 2020 · 4 comments · Fixed by #3
Assignees
Labels
enhancement New feature or request

Comments

@dauptaia
Copy link

dauptaia commented Oct 15, 2020

the display tree() is sweet, but i would need only the string output -without the print to the std_out-, because I must redirect it in a GUI log.

Smthg like
(display_tree_as_str()) -> the string repr of the tree.
I can easily code it myself, but It would be nicer to add this simple feature to the API surface of your pckg

Best regards

@dauptaia
Copy link
Author

dauptaia commented Oct 15, 2020

My current solution to make it clearer :

# Importing Libraries
import os
from pathlib import Path
from directory_tree import directory_path

# Main Method


class DirectoryPath(directory_path):
    """Wrapper of the directory_path class 

    Only to get a camel case Named Class.
    Yes I know I am a pep008 b***tch
    but I did search 30sec  where this directory_path was coming from
    """


def display_tree_as_str(dir_path=None):
    """return a display of the tree in a string

    By default, DIR_PATH is set to current working directory.
    """

    if dir_path is not None:
        dir_path = Path(dir_path)
    else:
        dir_path = Path(os.getcwd())

    out = str()
    paths = DirectoryPath.build_tree(dir_path)
    for path in paths:
        out += path.displayPath() + "\n"

    return out


if __name__ == '__main__':
    out = display_tree_as_str('.')
    print(out)

Thank you for providing the exact solution to my need anyway.

@rahulbordoloi
Copy link
Owner

@dauptaia, Hey Thanks for your Valuable Suggestions! I'll surely look into it towards the EOD or else you can put up a PR and I can merge it right straight away!

@rahulbordoloi rahulbordoloi added the enhancement New feature or request label Oct 15, 2020
@rahulbordoloi
Copy link
Owner

@dauptaia Check #3. New Functionality has been added. :)

@dauptaia
Copy link
Author

Works like a charm. Now a perfect fit for my needs. Thank you a lot!

@rahulbordoloi rahulbordoloi self-assigned this Oct 28, 2020
@rahulbordoloi rahulbordoloi linked a pull request Oct 28, 2020 that will close this issue
@rahulbordoloi rahulbordoloi pinned this issue Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants