Python物件說明的程式

From Dive Into Python:

def info(object, spacing=10, collapse=1):
"""Print methods 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.__doc__

與help function有相同功能,為help實作的範例。

February 2012

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      

Archives

Powered by Movable Type 4.34-en

About this Entry

This page contains a single entry by philipz published on August 31, 2008 9:28 PM.

使用 Ext、Aptana 和 AIR 构建桌面应用程序 was the previous entry in this blog.

另類的衛星地圖遊戲 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.