您的位置:首页 > 移动开发 > Objective-C

apihelper 查看属性和方法

2009-09-04 17:03 211 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息