def info(object,spacing=20,collapse=1):
"""print methods and doc string.
takes module,class,list,dictionary,or string."""
methodList=[method for method in dir(object) if hasattr(getattr(object,method),'__call__')]
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.__doc__)
Python3.1没有了callable 但是我们可以用hasattr(method,‘__call__')代替它
processFunc 如果你用type去查看 发现他是一个引用
而processFunc()这个函数呢 就相当与c++里面的 c?a:b
apihelper 查看属性和方法
最新推荐文章于 2023-11-14 22:02:25 发布