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 or enumerate etc…?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since Python is open source you can read the source code.
To find out what file a particular module or function is implemented in you can usually print the
__file__attribute. Alternatively, you may use theinspectmodule, see the section Retrieving Source Code in the documentation ofinspect.For built-in classes and methods this is not so straightforward since
inspect.getfileandinspect.getsourcewill return a type error stating that the object is built-in. However, many of the built-in types can be found in theObjectssub-directory of the Python source trunk. For example, see here for the implementation of the enumerate class or here for the implementation of thelisttype.