Where is __builtin__ module in CPython

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

+4
source share
3 answers

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

+5
source

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

+2
source

You can not. it is built into 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 the program, you can use the __file__ attribute, but the 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__' 
+2
source

Source: https://habr.com/ru/post/1339513/


All Articles