我在哪里可以找到 python 标准库代码? [英] Where do I find the python standard library code?

查看:68
本文介绍了我在哪里可以找到 python 标准库代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

解决方案

在 cpython 中,许多模块是用 C 实现的,而不是用 Python 实现的.您可以在 Modules/ 中找到它们,而纯 Python 位于 Lib/.>

在某些情况下(例如 json 模块),Python 源代码会自行提供该模块,并且仅在可用时才使用 C 模块(以提高性能).对于其余模块,您可以查看 PyPy 的实现.

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.

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

解决方案

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/.

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.

这篇关于我在哪里可以找到 python 标准库代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆