I found that python has an easy-to-use check module-inspect. Looking at the source file, I found that it provides a lot of useful methods:
""
Here are some of the useful functions provided by this module:
Ismodule (), isclass (), ismethod (), isfunction (), isgeneratorfunction (),
Isgenerator (), istraceback (), isframe (), iscode (), isbuiltin (), isroutine ()-check object types
Getmembers ()-Get members of an object that satisfy a given condition
GetFile (), getsourcefile (), getsource ()-find an object's source code
Getdoc (), getcomments ()-Get documentation on an object
Getmodule ()-determine the module that an object came from
Getclasstree ()-arrange classes so as to represent their hierarchy
Getargspec (), getargvalues ()-Get info about function arguments
Formatargspec (), formatargvalues ()-format an argument spec
Getouterframes (), getinnerframes ()-Get info about Frames
Currentframe ()-Get the current stack frame
Stack (), trace ()-Get info about frames on the stack or in a traceback
""
Example:
import inspectinspect.isbuiltin(abs)Trueimport osinspect.ismodule(os)Trueclass C:passinspect.isclass(C)Trueclass C(object): def foo(self): print 'here is foo' def bez(self): print 'here is bez'inspect.getmembers(C, inspect.ismethod)[('bez', "<"unbound method C.bez">"), ('foo', "<"unbound method C.foo">")]
If inspect. ismethod is not added, all default attributes of the object will be listed.
Other methods are listed one by one.
Original article: http://justpy.com/archives/tag/%E5%88%A4%E6%96%AD%E5%AF%B9%E8%B1%A1%E6%98%AF%E5%90%A6%E6%98%AF%E7%B1%BB