我对此代码有疑问,但不是没有原因......
import inspect
inspect.getsource(min)
,错误是:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
inspect.getsource(min)
File "C:\Python33\lib\inspect.py", line 726, in getsource
lines, lnum = getsourcelines(object)
File "C:\Python33\lib\inspect.py", line 715, in getsourcelines
lines, lnum = findsource(object)
File "C:\Python33\lib\inspect.py", line 551, in findsource
file = getfile(object)
File "C:\Python33\lib\inspect.py", line 435, in getfile
'function, traceback, frame, or code object'.format(object))
TypeError: <built-in function min> is not a module, class, method, function, traceback, frame,or code object
答案 0 :(得分:3)
内置的min()
是用C代码实现的,inspect.getsource()
只能显示 Python 代码:
>>> min
<built-in function min>
built-in function
类型始终在C中实现。
此功能的代码来自bltinmodule.c
源文件; builtin_min()
function委托给同一源文件中的min_max()
utility function。