我在哪里可以找到python标准库代码?

时间:2022-02-26 23:24:06

I wanted to try and look up the source of some of the modules in the Python standard library, but wasn't able to find them. I tried looking in the modules directory after downloading the python tarball, but it has mainly .c files. I also tried looking at the directory where the python that already comes with the OS (mac osx) has it's modules, and there it seems to have mainly .pyc and .pyo files. Would really appreciate it if someone can help me out.

我想尝试查找Python标准库中某些模块的源代码,但无法找到它们。下载python tarball后我尝试查看modules目录,但它主要有.c文件。我也尝试查看已经附带操作系统(mac osx)的python所在的目录,其中似乎主要有.pyc和.pyo文件。如果有人可以帮助我,真的很感激。

(I tried what was suggested in the question How do I find the location of Python module sources? with no luck)

(我尝试了问题中建议的如何找到Python模块源的位置?没有运气)

4 个解决方案

#1


29  

In cpython, many modules are implemented in C, and not in Python. You can find those in Modules/, whereas the pure Python ones reside in Lib/.

在cpython中,许多模块都是用C实现的,而不是用Python实现的。你可以在Modules /中找到它们,而纯Python的那些则驻留在Lib /中。

In some cases (for example the json module), the Python source code provides the module on its own and only uses the C module if it's available (to improve performance). For the remaining modules, you can have a look at PyPy's implementations.

在某些情况下(例如json模块),Python源代码自己提供模块,只有C模块可用(才能提高性能)。对于其余模块,您可以查看PyPy的实现。

#2


2  

The canonical repository for CPython is this Mercurial repository. There is also a git mirror on GitHub.

CPython的规范存储库是这个Mercurial存储库。 GitHub上还有一个git镜像。

#3


0  

Look it up under the Lib sub-directory of the Python installation directory.

在Python安装目录的Lib子目录下查找。

#4


-1  

You can get the source code of pure python modules that are part of the standard library from the location where Python is installed.

您可以从安装Python的位置获取纯python模块的源代码,这些模块是标准库的一部分。

For example at : C:\Python27\Lib (on windows) if you have used Windows Installer for Python Installation.

例如,如果您使用Windows Installer进行Python安装,则在:C:\ Python27 \ Lib(在Windows上)。

#1


29  

In cpython, many modules are implemented in C, and not in Python. You can find those in Modules/, whereas the pure Python ones reside in Lib/.

在cpython中,许多模块都是用C实现的,而不是用Python实现的。你可以在Modules /中找到它们,而纯Python的那些则驻留在Lib /中。

In some cases (for example the json module), the Python source code provides the module on its own and only uses the C module if it's available (to improve performance). For the remaining modules, you can have a look at PyPy's implementations.

在某些情况下(例如json模块),Python源代码自己提供模块,只有C模块可用(才能提高性能)。对于其余模块,您可以查看PyPy的实现。

#2


2  

The canonical repository for CPython is this Mercurial repository. There is also a git mirror on GitHub.

CPython的规范存储库是这个Mercurial存储库。 GitHub上还有一个git镜像。

#3


0  

Look it up under the Lib sub-directory of the Python installation directory.

在Python安装目录的Lib子目录下查找。

#4


-1  

You can get the source code of pure python modules that are part of the standard library from the location where Python is installed.

您可以从安装Python的位置获取纯python模块的源代码,这些模块是标准库的一部分。

For example at : C:\Python27\Lib (on windows) if you have used Windows Installer for Python Installation.

例如,如果您使用Windows Installer进行Python安装,则在:C:\ Python27 \ Lib(在Windows上)。