# NOTE: modified from here: https://code.activestate.com/recipes/137951-dump-all-the-attributes-of-an-object/ # to only print attributes def dumpObjAttr(obj): import types MethodWrapperType = type(object().__hash__) objclass = getattr(obj, '__class__') attrs = [] for slot in dir(obj): attr = getattr(obj, slot) if slot == '__class__': objclass = attr.__name__ elif slot == '__doc__': pass elif slot == '__module__': pass elif slot == '__dict__': pass elif slot == '__weakref__': pass elif (isinstance(attr, types.BuiltinMethodType) or isinstance(attr, MethodWrapperType)): pass elif (isinstance(attr, types.MethodType) or isinstance(attr, types.FunctionType)): pass else: attrs.append( (slot, attr) ) sOut = objclass + ':' for key, value in attrs: # NOTE: pretty print for long lists if isinstance(value, list) or isinstance(value, tuple): sOut += '\n\t' + key + ':' sOut += dumpList(value, 2) else: sOut += '\n\t' + key + ': ' + str(value) return sOut def dumpList(value, indent): s = '' if len(value) > 0: if isinstance(value[0], tuple): for k, v in value: s += '\n' + (indent * '\t') + k + ': ' + str(v) elif isinstance(value, list): for item in value: s += '\n' + (indent * '\t') + str(item) else: pass return s def getFunctionName(): import sys return sys._getframe(1).f_code.co_name