0

How can I open the underlying script for built-in functions? For example the function len.

I want to open the script of the len function to study how the underlying code is built, for educational purposes.

I have tried writing open(len) and open(len()), but I only get this error message:

Traceback (most recent call last):
File "C:/Users/someo/PycharmProjects/Test/test.py", line 1, in <module>
open(len())
TypeError: len() takes exactly one argument (0 given)
amab8901
  • 39
  • 1
  • 7

1 Answers1

0

These definitions can't be accessed, because they aren't part of a package. They live in Python itself, therefore they cannot be accessed. You can't get in by making them raise an error either (len(5) won't let you see inside the function, and will just raise a TypeError). Python itself won't show you the full traceback because these definitions aren't meant to be seen.

A random coder
  • 453
  • 4
  • 13
  • If you broke into Python's source, you wouldn't find Python, but instead C. These basic functions are as low as Python goes. – A random coder Jun 12 '21 at 18:41