Guest User

Untitled

a guest
Feb 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import types
  2.  
  3. def build_tree(start_point=None):
  4. if start_point is not None and type(start_point) is not types.ModuleType:
  5. print "start_point is not None (meaning use globals) and is not a module"
  6. check = [start_point]
  7. checked = set()
  8. tree = {}
  9. while len(check) > 0:
  10. current = check.pop(0)
  11. if current is None:
  12. d = globals()
  13. else:
  14. print "Popping %s" % current.__name__
  15. d = current.__dict__
  16. current_key = "globals()" if current is None else current.__name__
  17. for k, v in d.iteritems():
  18. if type(v) is types.ModuleType:
  19. if current_key not in tree:
  20. tree[current_key] = set()
  21. tree[current_key].add(v.__name__)
  22. if v not in checked:
  23. check.append(v)
  24. print "Appending %s" % v.__name__
  25. checked.add(current)
  26. return tree
Add Comment
Please, Sign In to add comment