Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获取内置模块的源代码?_Python - Fatal编程技术网

Python 如何获取内置模块的源代码?

Python 如何获取内置模块的源代码?,python,Python,模块或函数的源代码可以从inspect获得 import inspect print(inspect.getsource(moduleName.function)) 如果模块是内置模块呢 import sys print(inspect.getsource(sys)) TypeError: <module 'sys' (built-in)> is a built-in module . 导入系统 打印(inspect.getsource(sys)) TypeError:是一个内

模块或函数的源代码可以从inspect获得

import inspect
print(inspect.getsource(moduleName.function))
如果模块是内置模块呢

import sys
print(inspect.getsource(sys))

TypeError: <module 'sys' (built-in)> is a built-in module .
导入系统 打印(inspect.getsource(sys)) TypeError:是一个内置模块。
那我在哪里可以买到呢

sys模块是为数不多的几个模块之一,它不是用Python本身实现的,而是用本机代码实现的。C源位于中


大多数其他模块直接用Python实现。您可以在Python安装的
lib
目录中找到这些源代码,或者也可以。

@Sneftel在其周围放一些解释性的文字,这就是这个问题的正确答案。@Sneftel注意到这是一个半官方的镜像(当然有更好的UI),权威来源是位于@delnan Yeah的Mercurial存储库,但与Github相比,Hg web界面确实令人讨厌。值得半官方化。;-)@snetel当我在一周内必须查找多个内容时,我会克隆存储库并在本地进行查找(
ack grep
find
,以及类似的任何web界面)。