Python: traversing dependency tree
examples/python/project/traversing_dependency_tree.py
import sys import os if len(sys.argv) < 2: exit("Usage: {} NAME".format(sys.argv[0])) start = sys.argv[1] def get_dependencies(name): print("Processing {}".format(name)) deps = set(name) filename = name + ".txt" if not os.path.exists(filename): return deps with open(filename) as fh: for line in fh: row = line.rstrip("\n") deps.add(row) deps.update( get_dependencies(row) ) return deps dependencies = get_dependencies(start) print(dependencies)
examples/python/project/a.txt
b c d
examples/python/project/b.txt
e d
examples/python/project/a.txt
b c d
$ python traversing_dependency_tree.py a Processing a Processing b Processing e Processing d Processing c Processing f Processing g Processing d {'d', 'g', 'c', 'b', 'a', 'e', 'f'}
Published on 2019-07-19
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post