相关疑难解决方法(0)

查找内置Python函数的源代码?

有没有办法看到内置函数如何在python中工作?我不是指如何使用它们,而是它们是如何构建的,排序枚举背后的代码是什么......?

python python-internals

114
推荐指数
8
解决办法
9万
查看次数

带有传递的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 null python-2.x python-3.x

3
推荐指数
2
解决办法
335
查看次数

我怎样才能看到Python的__builtins__源代码?

我可以让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:"搜索并浏览了几个目录,但在几个目录后放弃了.

python built-in inspect python-2.7

2
推荐指数
1
解决办法
681
查看次数