The inspect module provides several useful functions to help get information about live objects such as modules, classes, methods, functions, tracebacks, frame objects, and code objects.
这个模块是针对模块,类,方法,功能等对象提供些有用的方法。
inspect模块的getargspec()方法正是用此判断来获取函数的特殊参数的。现在可以方便的获取__init__的**参数了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
结果为:
1 |
|
getmembers(object[, predicate])
返回一个包含对象的所有成员的(name, value)列表。返回的内容比对象的__dict__包含的内容多,源码是通过dir()实现的。
predicate是一个可选的函数参数,被此函数判断为True的成员才被返回。
getmodule(object)
返回定义对象的模块
getsource(object)
返回对象的源代码
getsourcelines(object)
返回一个元组,元组第一项为对象源代码行的列表,第二项是第一行源代码的行号