This commit is contained in:
Dave Schuyler 2005-02-25 23:13:09 +00:00
parent 429a075c79
commit b78fb88cf3

View File

@ -141,6 +141,33 @@ def printThisCall():
return 1 # to allow "assert printThisCall()"
if __debug__:
def lineage(obj, verbose=0, indent=0):
"""
return instance or class name in as a multiline string.
Usage: print lineage(foo)
(Based on getClassLineage())
"""
r=""
if type(obj) == types.ListType:
r+=(" "*indent)+"python list\n"
elif type(obj) == types.DictionaryType:
r+=(" "*indent)+"python dictionary\n"
elif type(obj) == types.ModuleType:
r+=(" "*indent)+str(obj)+"\n"
elif type(obj) == types.InstanceType:
r+=lineage(obj.__class__, verbose, indent)
elif type(obj) == types.ClassType:
r+=(" "*indent)
if verbose:
r+=obj.__module__+"."
r+=obj.__name__+"\n"
for c in obj.__bases__:
r+=lineage(c, verbose, indent+2)
return r
def tron():
sys.settrace(trace)
def trace(frame, event, arg):