如何找到内置功能代码? [重复]

问题描述 投票:2回答:1

我只想看一下内置的功能代码。因为我是Python的初学者,所以我认为一些源代码可以给我非常有用的指导。我做了一些测试代码,如下所示,并使用PyCharm IDE对“ join”进行了“ Ctrl + click”操作。

zip_command = "zip -r {0} {1}".format(target, ' '.join(source))

然后光标指向builtin.py模块的连接功能,但是有空代码。只有一个解释。这是如何运作的?真正的代码在哪里?

def join(self, ab=None, pq=None, rs=None): # real signature unknown; restored from __doc__
    """
    Concatenate any number of strings.

    The string whose method is called is inserted in between each given string.
    The result is returned as a new string.

    Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
    """
    pass

'builtin.py'路径为:C:\ Users \ admin.PyCharmCE2019.3 \ system \ python_stubs \ 542861396 \ builtins.py

python built-in
1个回答
1
投票

[str.join()在C中实现,特别是在unicodeobject.cunicode_join中实现。

“如何找到内置函数和对象的源代码”没有很好的答案。有关CPython布局的一些概述,请参见unicode_join。虽然Python的某些标准库是用Python编写的(位于Finding the source code for built-in Python functions?中),但您会发现内置库和标准库中一些对性能敏感的组件都具有C实现。前者位于lib/,后者位于objects/

© www.soinside.com 2019 - 2024. All rights reserved.