Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see Python's __builtins__ source code?

Can I get python to print the source code for __builtins__ directly?

OR (more preferably):

What is the pathname of the source code for __builtins__?


I at least know the following things:

  • __builtins__ is a module, by typing type(__builtins__).

  • I have tried the best-answer-suggestions to a more general case of this SO question: "Finding the source code for built-in Python functions?". But no luck:

    • print inspect.getdoc(__builtins__) just gives me a description.

    • inspect.getfile(__builtins__) just gives me an error: TypeError: <module '__builtin__' (built-in)> is a built-in module

    • https://hg.python.org/cpython/file/c6880edaf6f3/# does not seem to contain an entry for __builtins__. I've tried "site:" search and browsed several of the directories but gave up after a few.


1 Answers

The __builtin__ module is implemented in Python/bltinmodule.c, a rather unusual location for a rather unusual module.

like image 53
user2357112 supports Monica Avatar answered Dec 07 '25 00:12

user2357112 supports Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!