Python中的__builtin__模块在哪里?

时间:2011-02-13 01:59:06

标签: python cpython

我想获取__builtin__模块的路径和源代码,我在哪里可以获得它?

3 个答案:

答案 0 :(得分:5)

__builtin__模块的最新(主干)C来源:http://svn.python.org/view/python/trunk/Python/bltinmodule.c?view=markup

答案 1 :(得分:2)

__builtin__模块是内置的,没有Python源代码。它以C编码,并作为Python解释器可执行文件的一部分包含在内。

答案 2 :(得分:2)

你做不到。它内置于翻译。

>>> # 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)>

在程序中,您可以使用__file__属性,但内置模块没有。

>>> 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__'