-
Notifications
You must be signed in to change notification settings - Fork 13
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
Labels
enhancement
New feature or request
Comments
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. |
@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! |
Works like a charm. Now a perfect fit for my needs. Thank you a lot! |
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
The text was updated successfully, but these errors were encountered: