I tried to lookup in all the directories listed in sys.path
but I couldn't find any builtins.py
file, so where is it?
Built-in modules are written in C and integrated with the Python shell. Each built-in module contains resources for certain system-specific functionalities such as OS management, disk IO, etc. The standard library also contains many Python scripts (with the . py extension) containing useful utilities.
The built-in function dir() returns a list of names of attributes, methods, etc. of the object specified in the argument. You can get a list of names of built-in objects, such as built-in functions and constants, by passing the builtins module or __builtins__ to dir() . To make the output easier to read, use pprint.
This module provides direct access to all 'built-in' identifiers of Python; for example, builtins. open is the full name for the built-in function open() . See Built-in Functions and Built-in Constants for documentation.
Literally the module is built-in to the python interpreter.
>>> import builtins
>>> builtins
<module 'builtins' (built-in)>
>>> import sys
>>> sys
<module 'sys' (built-in)>
Such modules are represented with (built-in)
as you can see in the above interactive session.
If the module is loaded from file, it will be represented as follow:
>>> import ftplib
>>> ftplib
<module 'ftplib' from 'C:\\Python34\\lib\\ftplib.py'>
UPDATE You can find builtins module's code in Python/bltinmodule.c
from the Python source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With