Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import types
- def build_tree(start_point=None):
- if start_point is not None and type(start_point) is not types.ModuleType:
- print "start_point is not None (meaning use globals) and is not a module"
- check = [start_point]
- checked = set()
- tree = {}
- while len(check) > 0:
- current = check.pop(0)
- if current is None:
- d = globals()
- else:
- print "Popping %s" % current.__name__
- d = current.__dict__
- current_key = "globals()" if current is None else current.__name__
- for k, v in d.iteritems():
- if type(v) is types.ModuleType:
- if current_key not in tree:
- tree[current_key] = set()
- tree[current_key].add(v.__name__)
- if v not in checked:
- check.append(v)
- print "Appending %s" % v.__name__
- checked.add(current)
- return tree
Add Comment
Please, Sign In to add comment