Finding the source code for built-in Python functions?

前端 未结 8 1659
一向
一向 2020-11-22 02:40

Is there a way to see how built in functions work in python? I don\'t mean just how to use them, but also how were they built, what is the code behind sorted

8条回答
  •  [愿得一人]
    2020-11-22 02:49

    Here is a cookbook answer to supplement @Chris' answer, CPython has moved to GitHub and the Mercurial repository will no longer be updated:

    1. Install Git if necessary.
    2. git clone https://github.com/python/cpython.git

    3. Code will checkout to a subdirectory called cpython -> cd cpython

    4. Let's say we are looking for the definition of print()...
    5. egrep --color=always -R 'print' | less -R
    6. Aha! See Python/bltinmodule.c -> builtin_print()

    Enjoy.

提交回复
热议问题