Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the __builtin__ module in CPython

Tags:

python

cpython

I want to get the path and source code of the __builtin__ module, where can I get it?

like image 358
Thomson Avatar asked Feb 13 '11 01:02

Thomson


3 Answers

Latest (trunk) C sources of __builtin__ module: http://svn.python.org/view/python/trunk/Python/bltinmodule.c?view=markup

like image 174
ulidtko Avatar answered Nov 18 '22 11:11

ulidtko


The __builtin__ module is built-in, there is no Python source for it. It's coded in C and included as part of the Python interpreter executable.

like image 41
Ned Batchelder Avatar answered Nov 18 '22 12:11

Ned Batchelder


You can't. it is built-in to the interpreter.

>>> # os is from '/usr/lib/python2.7/os.pyc'
>>> import os
>>> os
<module 'os' from '/usr/lib/python2.7/os.pyc'>
>>> # PyQt4 is from '/usr/lib/python2.7/site-packages/PyQt4/__init__.pyc'
>>> import PyQt4
>>> PyQt4
<module 'PyQt4' from '/usr/lib/python2.7/site-packages/PyQt4/__init__.pyc'>
>>> # __builtin__ is built-in
>>> import __builtin__
>>> __builtin__
<module '__builtin__' (built-in)>

In a program, you could use the __file__ attribute, but built-in modules do not have it.

>>> os.__file__
'/usr/lib/python2.7/os.pyc'
>>> PyQt4.__file__
'/usr/lib/python2.7/site-packages/PyQt4/__init__.pyc'
>>> __builtin__.__file__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__file__'
like image 2
Artur Gaspar Avatar answered Nov 18 '22 10:11

Artur Gaspar