哪些本机 python 模块是用 C 编写的?

Chi*_*nke 5 c python

我打算用 python 编写一个小型文本编辑器。因此,我需要一个快速的字符串操作/文本处理库,出于性能原因,最好用 C 编写。

我如何知道哪些 python 模块是在底层用 C 编写的?

las*_*koi 5

就像 Gene 推荐的那样,最好的方法是查看源代码并找出哪些模块是用 C 实现的。

您可以检查__file__模块的属性:

>>> import math
>>> print(math.__file__)
/usr/lib/python2.7/lib-dynload/math.so
Run Code Online (Sandbox Code Playgroud)

在此示例中,它是一个.so已加载的文件,因此该模块是用编译语言(最有可能是 C)实现的。