python 自省(摘自 dive into python)

xiaoxiao2025-12-13  5

def info(object, spacing=10,collapse=1): """ print methos and doc strings. takes module,class,list,dictionary,or string. """ methodList = [method for method in dir(object) if callable(getattr(object,method))] processFunc = collapse and (lambda s : "".join(s.split())) or (lambda s: s) print "\n".join(["%s %s" %(method.ljust(spacing), processFunc(str(getattr(object,method).__doc__))) for method in methodList ]) if __name__ == "__main__" : print info(dict) 相关资源:diveintopython3_---《深入python3》
转载请注明原文地址: https://www.6miu.com/read-5040822.html

最新回复(0)