张小刀

人生苦短……

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 1 def info(object, spacing=10, collapse=1):
 2     """Print methods and doc strings.
 3     
 4     Takes module, class, list, dictionary, or string."""
 5     methodList = [method for method in dir(object) if callable(getattr(object, method))]
 6     processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
 7     print "\n".join(["%s %s" %
 8                       (method.ljust(spacing),
 9                        processFunc(str(getattr(object, method).__doc__)))
10                      for method in methodList])

 

posted on 2014-08-14 23:16  张小刀  阅读(173)  评论(0编辑  收藏  举报