Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is builtins module located?

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?

like image 822
zer0uno Avatar asked Aug 09 '14 13:08

zer0uno


People also ask

Where is the Builtins module in Python?

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.

How do I see Builtins in Python?

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.

What is Builtins object in Python?

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.


1 Answers

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.

like image 143
falsetru Avatar answered Oct 19 '22 11:10

falsetru