{ "info": { "author": "Weitang Li", "author_email": "liwt31@163.com", "bugtrack_url": null, "classifiers": [], "description": "# print_tree\n[![Build Status](https://travis-ci.org/liwt31/print_tree.svg?branch=master)](https://travis-ci.org/liwt31/print_tree)\n[![PyPI version](https://badge.fury.io/py/print-tree2.svg)](https://badge.fury.io/py/print-tree2)\n\nThis package helps you to print your tree structure in a pretty format.\n\n\n### Install\n```\npip install print-tree2\n```\nI wish to use `print_tree` as the name but the package is already on pypi though it's not working.\nTo verify your installation, try:\n```\ngit clone https://github.com/liwt31/print_tree.git\ncd print_tree/\npytest\n```\n\n### Features\nThere is already a pretty print tree lib on GitHub [pptree](https://github.com/clemtoy/pptree), why reinvent another wheel?\nThe most important reason is:\n* **This package provides an inherit interface that does not require you to modify any of your code**, while [pptree](https://github.com/clemtoy/pptree) by design requires your node class to have certain methods or properties.\n\nBesides, this package:\n* Does not change the order of your children ([pptree](https://github.com/clemtoy/pptree) does).\n* Uses Unicode to achieve cross-platform -- [pptree](https://github.com/clemtoy/pptree) fails on Windows because of wider space on terminals.\n* Supports colored terminal strings (Only for Linux currently) and full-width characters.\n\nStill, **[pptree](https://github.com/clemtoy/pptree) is a wonderful package**. The implementation is really beautiful and I borrowed some ideas from the author.\n\n### Documentation\nThe `print*.py` files in the `example` directory provides several examples on how to use the package. And below can be regard as an explanation of these files. The files in `example` directory enabled coloring to demonstrate the ability of this package to print tree with colors. Because the effect can not be seen in this MD file, corresponding codes are ommited.\nSuppose we have the `Node` class:\n```\nclass Node(object):\n\n def __init__(self, value, parent):\n self.value = value\n self.children = []\n if parent is not None:\n parent.children.append(self)\n```\nAs an example, let's construct a tree as follows:\n```\ndata_structure = Node('Data Stucture', None)\n\nvector = Node('Vector', data_structure)\nlist_ = Node('List', data_structure)\ntree = Node('Tree', data_structure)\ngraph = Node('Graph', data_structure)\n\ndag = Node('DAG', graph)\navl = Node('AVL', tree)\nsplay = Node('Splay', tree)\nb = Node('B', tree)\nquad = Node('Quand', tree)\nkd = Node('kd', tree)\n```\nTo print the tree, we have to tell `print_tree` two things:\n1. how to transverse the tree from the root node.\n2. how to interpret every node as a string. \n\nTo achieve these goals, we inherent `print_tree` from the package then override `get_children` and `get_node_str`:\n```\nfrom print_tree import print_tree\n\nclass print_custom_tree(print_tree):\n\n def get_children(self, node):\n return node.children\n\n def get_node_str(self, node):\n return str(node.value)\n```\n`get_children` should accept a `Node` and return a list with element type `Node` or `PlaceHolder` (see below for more info on `PlaceHolder`), and `get_node_str` accept a `Node` and return a string. Then we can use `print_custom_tree` as if it's a function:\n```\n>>> print_custom_tree(data_structure)\n\n \u250cVector\n \u251cList\nData Stucture\u2524\n \u2502 \u250cAVL\n \u2502 \u251cSplay\n \u251cTree\u253cB\n \u2502 \u251cQuand\n \u2502 \u2514kd\n \u2514Graph\u2500DAG\n```\nIf you feel uncomfortable about the naming of the class, you can import `PrintTree` then use `PrintTree` instead. \n\nNow let's move on to some more complex examples. In the `example` directory I have defined a primitive search tree with custom numbers of branch. For brevity only the `__init__` function of the `Node` is shown here. If `branch == 2` then it's a binary search tree.\n```\nclass Node(object):\n\n def __init__(self, value, branch):\n self.values = [value]\n self.branch = branch\n self.children = [None] * branch\n```\nIf we wish to emphasize on the *binary* structure, we can override `get_children` and `get_node_str` as follows:\n```\nclass print_binary(print_tree):\n def get_children(self, node):\n l_child, r_child = node.children\n if r_child is None and l_child is None:\n return []\n else:\n r_child = r_child or PlaceHolder\n l_child = l_child or PlaceHolder\n return [r_child, l_child]\n\n def get_node_str(self, node):\n return str(node.values[0])\n```\nIn this case it is possible that the return list of `get_children` contains `PlaceHolder`, which can be directly imported by `from print_tree import PlaceHolder`. If `PlaceHolder` is in the return list, `print_tree` will take it as a placeholder: nothing will be shown, but it takes blank space:\n```\n# Tree (bst) already initialized\n>>> print_binary(bst.root)\n\n \u2001 \u2001 \u250c19\u2510\n \u2001 \u2001 \u2502 \u2502 \u250c18\n \u2001 \u2001 \u2502 \u251417\u2524\n \u2001 \u2001 \u2502 \u2001 \u2502 \u250c16\n \u2001 \u2001 \u2502 \u2001 \u251415\u2518\n \u2001 \u2001 \u2502 \u2001 \u2001 \n \u2001 \u2001 \u2502 \u2001 \u2001 \n \u2001 \u250c14\u2524\n \u2001 \u2502 \u251413\n \u250c12\u2518\n \u2502 \n \u2502 \n11\u2524\n \u2502 \u2001 \u2001 \u250c10\n \u2502 \u2001 \u250c9\u2524\n \u2502 \u2001 \u2502 \u25148\n \u2502 \u250c7\u2524\n \u2502 \u2502 \u2502 \u2001 \u250c6\n \u2502 \u2502 \u2502 \u250c5\u2524\n \u2502 \u2502 \u2502 \u2502 \u2502 \u250c4\n \u2502 \u2502 \u2502 \u2502 \u25143\u2518\n \u2502 \u2502 \u2502 \u2502 \u2001 \n \u2502 \u2502 \u25142\u2524\n \u2502 \u2502 \u2001 \u25141\n \u25140\u2518\n```\nBecause the tree is randomly generated, the result is probably different from what you saw when you test your installation. However, in both cases, you can read the inorder transverse of the tree from bottom to top as `list(range(20))` (0 to 19).\nThe effect of `PlaceHolder` becomes prominent after we delete them (also note on the benefit of inheritance):\n```\nclass print_binary_without_placeholder(print_binary):\n def get_children(self, node):\n l_child, r_child = node.children\n children = []\n if r_child is not None:\n children.append(r_child)\n if l_child is not None:\n children.append(l_child)\n return children\n\n# initialize the tree(bst)\n...\n\nprint_binary_without_placeholder(bst.root)\n\n \u2001 \u2001 \u2001 \u2001 \u250c18\n \u2001 \u2001 \u250c19\u250017\u2524\n \u2001 \u2001 \u2502 \u2001 \u251415\u250016\n \u250c12\u250014\u2524\n \u2502 \u2001 \u251413\n11\u2524\n \u2502 \u2001 \u2001 \u250c10\n \u2502 \u2001 \u250c9\u2524\n \u2502 \u2001 \u2502 \u25148\n \u25140\u25007\u2524\n \u2001 \u2001 \u2502 \u2001 \u250c6\n \u2001 \u2001 \u2502 \u250c5\u2524\n \u2001 \u2001 \u2502 \u2502 \u25143\u25004\n \u2001 \u2001 \u25142\u2524\n \u2001 \u2001 \u2001 \u25141\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/liwt31/print-tree", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "print-tree2", "package_url": "https://pypi.org/project/print-tree2/", "platform": "", "project_url": "https://pypi.org/project/print-tree2/", "project_urls": { "Homepage": "https://github.com/liwt31/print-tree" }, "release_url": "https://pypi.org/project/print-tree2/0.9.10/", "requires_dist": [ "ipython" ], "requires_python": "", "summary": "Print trees", "version": "0.9.10" }, "last_serial": 4452034, "releases": { "0.9.1": [ { "comment_text": "", "digests": { "md5": "6047f4688fca96c03ce42e976e892d37", "sha256": "1a7c103e3ae6b4341c96c8e668444902b2286b4c329279ade112bf78c4730681" }, "downloads": -1, "filename": "print_tree2-0.9.1-py3-none-any.whl", "has_sig": false, "md5_digest": "6047f4688fca96c03ce42e976e892d37", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3244, "upload_time": "2018-10-15T13:39:35", "url": "https://files.pythonhosted.org/packages/fe/d2/ec3fd50a203fda64a60d97627f544182b4b938d1e7290323932fd116b844/print_tree2-0.9.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e150545f0e0b1c7d8faf01a5de8db3e5", "sha256": "34c69ab81ccb7cd19d83adf2f7855bbeed08a1c5c136b1aaeae1a3dd5345407e" }, "downloads": -1, "filename": "print_tree2-0.9.1.tar.gz", "has_sig": false, "md5_digest": "e150545f0e0b1c7d8faf01a5de8db3e5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3918, "upload_time": "2018-10-15T13:39:49", "url": "https://files.pythonhosted.org/packages/ca/1b/2327d5a39e6d9df46aa092e09e033f6fb852057a6ecf9fe61fe0623907bc/print_tree2-0.9.1.tar.gz" } ], "0.9.10": [ { "comment_text": "", "digests": { "md5": "cea3d486037cdb32761948bc37e3ebf9", "sha256": "f9dab7e8814c0229bf52fb59c85a4c475834ac557dbedac60ae8b0d112f9c453" }, "downloads": -1, "filename": "print_tree2-0.9.10-py3-none-any.whl", "has_sig": false, "md5_digest": "cea3d486037cdb32761948bc37e3ebf9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9087, "upload_time": "2018-11-05T08:25:22", "url": "https://files.pythonhosted.org/packages/dd/1a/e078e0b9c9e005f0a77688b54912aa66f0c4eb9fa7c6d32180dbbf9590b6/print_tree2-0.9.10-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "08360faabcb149d1892f4448146485ef", "sha256": "ced500304083bebc56014207899c8f6cbee5c79c571ea598b03ac2a23c5698ec" }, "downloads": -1, "filename": "print-tree2-0.9.10.tar.gz", "has_sig": false, "md5_digest": "08360faabcb149d1892f4448146485ef", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6673, "upload_time": "2018-11-05T08:25:24", "url": "https://files.pythonhosted.org/packages/d7/b2/085516b5b5735d14b6113a1f601c36915e36e8c2a239de6a8fe32dfff8e6/print-tree2-0.9.10.tar.gz" } ], "0.9.3": [ { "comment_text": "", "digests": { "md5": "c4c5abd8eb7ad9418403553faf71b5c7", "sha256": "c3674900cad2f1a8541641f4a2e7a69e006c542bccb5ac732d669fbec7795c2d" }, "downloads": -1, "filename": "print_tree2-0.9.3-py3-none-any.whl", "has_sig": false, "md5_digest": "c4c5abd8eb7ad9418403553faf71b5c7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5485, "upload_time": "2018-10-15T14:16:56", "url": "https://files.pythonhosted.org/packages/83/f8/f59fa8fffde8a2524095dbdcf2028928a4d6f2caba49c6589b48c8fc9f6b/print_tree2-0.9.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "87a908b54c55e2bbd4c042671e7f6931", "sha256": "2e11a7a3b7be386f2959a0d517f2c0523250accbd0eb21809147d9a2a24ed7e6" }, "downloads": -1, "filename": "print_tree2-0.9.3.tar.gz", "has_sig": false, "md5_digest": "87a908b54c55e2bbd4c042671e7f6931", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4619, "upload_time": "2018-10-15T14:16:58", "url": "https://files.pythonhosted.org/packages/af/4a/a514b3cad4cfc152ada97b1e9df5054d3ce7cd30dfbd8de96b0be31a58d0/print_tree2-0.9.3.tar.gz" } ], "0.9.4": [ { "comment_text": "", "digests": { "md5": "e1c44afff377975fa82deecfb3f6d8e1", "sha256": "93e0e90f7f57e8106ef11742a7e4590d618facfc09c4fd2bd576671ddff96296" }, "downloads": -1, "filename": "print_tree2-0.9.4-py3-none-any.whl", "has_sig": false, "md5_digest": "e1c44afff377975fa82deecfb3f6d8e1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3362, "upload_time": "2018-10-15T14:33:50", "url": "https://files.pythonhosted.org/packages/d7/dc/0c3134bf7af857d1cf56d7f57d9d2a08c0c9bff239c1291509f47a72d736/print_tree2-0.9.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "94000fe6b38b2c2908aec8eb6bd65e40", "sha256": "0e98b75081497b97db0c9fb94e8f071504c8eba5af06546f619a5d45f3fe156e" }, "downloads": -1, "filename": "print_tree2-0.9.4.tar.gz", "has_sig": false, "md5_digest": "94000fe6b38b2c2908aec8eb6bd65e40", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4697, "upload_time": "2018-10-15T14:33:52", "url": "https://files.pythonhosted.org/packages/a9/55/ea707248d67e6e59bd5cd30427a1932abdf6e00c1d36f56b7b10fc38f51c/print_tree2-0.9.4.tar.gz" } ], "0.9.5": [ { "comment_text": "", "digests": { "md5": "2992e2a787ae4f87d59e83a6cdfa3671", "sha256": "0ff8d56c10ecc6b8bac9ea1c0daeaf04f283686e0f1472a26d2fc495f8bf13c0" }, "downloads": -1, "filename": "print_tree2-0.9.5-py3-none-any.whl", "has_sig": false, "md5_digest": "2992e2a787ae4f87d59e83a6cdfa3671", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3348, "upload_time": "2018-10-16T02:01:25", "url": "https://files.pythonhosted.org/packages/aa/82/b57faedc079ba55029fd13fcac668d61e77584a02ad05ddc9e1572a697b0/print_tree2-0.9.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d72e1ed50cd799e0d2b5d4e6968099d9", "sha256": "aa9aa88a5078f72a3c470eac5999403d1cd1a1b1be570fd2e287409240cbaa00" }, "downloads": -1, "filename": "print_tree2-0.9.5.tar.gz", "has_sig": false, "md5_digest": "d72e1ed50cd799e0d2b5d4e6968099d9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4693, "upload_time": "2018-10-16T02:01:27", "url": "https://files.pythonhosted.org/packages/53/3f/4691bdb91fbbc6e2578666454c1341efb6fff9e6df5adf6d2ad7535497c8/print_tree2-0.9.5.tar.gz" } ], "0.9.6": [ { "comment_text": "", "digests": { "md5": "cb133cd3341ac8bcf68df64facac3565", "sha256": "a7b999293a1bbd65324a5460c248401284a69f6be5f90dc2339c87ff067f7670" }, "downloads": -1, "filename": "print_tree2-0.9.6-py3-none-any.whl", "has_sig": false, "md5_digest": "cb133cd3341ac8bcf68df64facac3565", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5474, "upload_time": "2018-10-16T02:09:17", "url": "https://files.pythonhosted.org/packages/8f/87/3f7bd443dff702a1f58f9e3c81d6dcd8231e629136f0623172a59c7539b1/print_tree2-0.9.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3c24f30acd26447457e1c7e5cdcadae4", "sha256": "be52960893843f09dec1fb7ab5190cb11c686071c930644d505065925f0cc3d3" }, "downloads": -1, "filename": "print_tree2-0.9.6.tar.gz", "has_sig": false, "md5_digest": "3c24f30acd26447457e1c7e5cdcadae4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4657, "upload_time": "2018-10-16T02:09:18", "url": "https://files.pythonhosted.org/packages/96/99/ec283fc99c86bf9b0117caa8e3f3b2723ad9fd1e0721fda8b148b1b90ff9/print_tree2-0.9.6.tar.gz" } ], "0.9.7": [ { "comment_text": "", "digests": { "md5": "7c35949dce24d1daf8a1f8eb97e36424", "sha256": "9675b5d300c9b582c360d5630707e19a00aa4af218b5f69cab1ae04c25c37120" }, "downloads": -1, "filename": "print_tree2-0.9.7-py3-none-any.whl", "has_sig": false, "md5_digest": "7c35949dce24d1daf8a1f8eb97e36424", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5470, "upload_time": "2018-10-16T12:47:13", "url": "https://files.pythonhosted.org/packages/4b/a7/09b3613b4e3adcb9670b02656acad5388698e2659da6333fa46397800f3f/print_tree2-0.9.7-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f18c503bbc403422a8670d33cb10ddba", "sha256": "d8b1d6112651f86e7df6181c07f2521babb0c8d001d6358ace1af48c48bfab1e" }, "downloads": -1, "filename": "print_tree2-0.9.7.tar.gz", "has_sig": false, "md5_digest": "f18c503bbc403422a8670d33cb10ddba", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4660, "upload_time": "2018-10-16T12:47:14", "url": "https://files.pythonhosted.org/packages/ac/05/39276e70471445601fb70b95a29d2e0af9e097650c8339cbffd0f2cc27a8/print_tree2-0.9.7.tar.gz" } ], "0.9.8": [ { "comment_text": "", "digests": { "md5": "635eee6df418cb43906317f4b1df723d", "sha256": "c1dff8645f78c96f9f695702ed99cb56b5228f07aa48647cfdda3cae385a969a" }, "downloads": -1, "filename": "print_tree2-0.9.8-py3-none-any.whl", "has_sig": false, "md5_digest": "635eee6df418cb43906317f4b1df723d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8851, "upload_time": "2018-11-03T12:44:32", "url": "https://files.pythonhosted.org/packages/3e/b4/3e317fb653cdb2dee83007be92fb19dd5efc0cac54afa558124e70fd2a20/print_tree2-0.9.8-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "455737dcdcaad37c3346158c68aa006a", "sha256": "4ff593501b776794a6d33d7be24ab7ac3dd84417e507f7afea182e8e7e9a0dfd" }, "downloads": -1, "filename": "print_tree2-0.9.8.tar.gz", "has_sig": false, "md5_digest": "455737dcdcaad37c3346158c68aa006a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6416, "upload_time": "2018-11-03T12:44:34", "url": "https://files.pythonhosted.org/packages/42/28/98ea14fea32f8e940a3336465832e0e9813c31912d4a22688ed013576a59/print_tree2-0.9.8.tar.gz" } ], "0.9.9": [ { "comment_text": "", "digests": { "md5": "5dc65daa2010992726b02a43ace63f9c", "sha256": "b0c59ac67cf0123fc5dcfc4ec29c4511694fc6687e5fed3d4445698cd256b325" }, "downloads": -1, "filename": "print_tree2-0.9.9-py3-none-any.whl", "has_sig": false, "md5_digest": "5dc65daa2010992726b02a43ace63f9c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8978, "upload_time": "2018-11-03T13:21:43", "url": "https://files.pythonhosted.org/packages/dc/41/c86141208cf8c370d404ccb289337398814ca24932cb5d708af9e423e415/print_tree2-0.9.9-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c8f275724a6b9ce2d6e989bc2738e6eb", "sha256": "0a295fc10c7d9bd82f020a204317e83d31df1f1d519711b2b15cebafe78473c6" }, "downloads": -1, "filename": "print-tree2-0.9.9.tar.gz", "has_sig": false, "md5_digest": "c8f275724a6b9ce2d6e989bc2738e6eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6540, "upload_time": "2018-11-03T13:21:45", "url": "https://files.pythonhosted.org/packages/1c/2d/e0bf445c25ab5b73f3668aad16571719427dfaf05a09b107235896485fd8/print-tree2-0.9.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cea3d486037cdb32761948bc37e3ebf9", "sha256": "f9dab7e8814c0229bf52fb59c85a4c475834ac557dbedac60ae8b0d112f9c453" }, "downloads": -1, "filename": "print_tree2-0.9.10-py3-none-any.whl", "has_sig": false, "md5_digest": "cea3d486037cdb32761948bc37e3ebf9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9087, "upload_time": "2018-11-05T08:25:22", "url": "https://files.pythonhosted.org/packages/dd/1a/e078e0b9c9e005f0a77688b54912aa66f0c4eb9fa7c6d32180dbbf9590b6/print_tree2-0.9.10-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "08360faabcb149d1892f4448146485ef", "sha256": "ced500304083bebc56014207899c8f6cbee5c79c571ea598b03ac2a23c5698ec" }, "downloads": -1, "filename": "print-tree2-0.9.10.tar.gz", "has_sig": false, "md5_digest": "08360faabcb149d1892f4448146485ef", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6673, "upload_time": "2018-11-05T08:25:24", "url": "https://files.pythonhosted.org/packages/d7/b2/085516b5b5735d14b6113a1f601c36915e36e8c2a239de6a8fe32dfff8e6/print-tree2-0.9.10.tar.gz" } ] }