有没有办法看到内置函数如何在python中工作?我不是指如何使用它们,而是它们是如何构建的,排序或枚举背后的代码是什么......?
在许多代码中,我看到其中包含函数的类,他们只是使用了pass短语并对其进行了一些评论.像python中的本机内置函数:
def copyright(*args, **kwargs): # real signature unknown
"""
interactive prompt objects for printing the license text, a list of
contributors and the copyright notice.
"""
pass
Run Code Online (Sandbox Code Playgroud)
我知道传球无所作为,它的那种冷漠和null短语,但为什么程序员使用这样的功能?
还有一些功能return ""如下:
def bin(number): # real signature unknown; restored from __doc__
"""
bin(number) -> string
Return the binary representation of an integer.
>>> bin(2796202)
'0b1010101010101010101010'
"""
return ""
Run Code Online (Sandbox Code Playgroud)
为什么程序员会使用这些东西?
我可以让python直接打印源代码__builtins__吗?
或(更优选):
源代码的路径名是什么__builtins__?
我至少知道以下事情:
__builtins__是一个模块,通过键入type(__builtins__).
我已经尝试了最好的答案建议来解决这个问题的一般情况:"找到内置Python函数的源代码?" .但没有运气:
print inspect.getdoc(__builtins__) 只是给我一个描述.
inspect.getfile(__builtins__) 只是给我一个错误: TypeError: <module '__builtin__' (built-in)> is a built-in module
https://hg.python.org/cpython/file/c6880edaf6f3/#似乎没有包含条目__builtins__.我尝试了"site:"搜索并浏览了几个目录,但在几个目录后放弃了.