How can I find the builtin function code?

Viewed 283

I just want to take a look builtin function code. Because I'm a beginner on Python and I think some source code can give me very useful instruction. I made some test code as follows and I did 'Ctrl+click' on 'join' with PyCharm IDE.

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

And then cursor points builtin.py module's join function, but there is empty code. There is only an explanation. How does this operate? Where is the real code?

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' path is : C:\Users\admin.PyCharmCE2019.3\system\python_stubs\542861396\builtins.py

1 Answers

str.join() is implemented in C, specifically in unicodeobject.c at unicode_join.

"How can I find the source code for builtin functions and objects" doesn't have a great answer. See Finding the source code for built-in Python functions? for some overviews of how CPython is laid out. While some of Python's standard library is written in Python (this sits in lib/), you'll find that builtins and some performance-sensitive components of the standard library have a C implementation. The former resides in objects/, and the latter in modules/.

Related