Reputation: 43
I have a problem with this code , but don't no why...
import inspect
inspect.getsource(min)
and the error is:
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
Upvotes: 2
Views: 2508
Reputation: 1121834
The built-in min()
is implemented in C code, and inspect.getsource()
can only show you Python code:
>>> min
<built-in function min>
The built-in function
type is always implemented in C.
The code for this function comes from the bltinmodule.c
source file; the builtin_min()
function delegates to the min_max()
utility function in the same source file.
Upvotes: 6