【问题标题】:View Python source code of the standard library and external libraries [closed]查看标准库和外部库的 Python 源代码 [关闭]
【发布时间】:2019-09-12 16:30:48
【问题描述】:

如何查看特定标准库和/或外部库的源代码?我想查看 Python 代码,而不是底层 C 代码。

我试图找到这个来看看有经验的程序员是如何编写他们的代码的。我已经查看了Where do I find the python standard library code?,但答案似乎大部分是用 C 编写的。

【问题讨论】:

  • 这取决于模块,但有些是用 C 编写的,你会发现没有 Python 代码。对于用 Python 编写的模块,您可以导入它并检查其__file__ 属性:import numpy; numpy.__file__
  • 部分模块是用C编写的(假设你使用的是python的C实现)并且没有python代码。
  • IPython 中一个有用的相关实用程序是,如果您键入 something??,其中something 是 Python 函数、类或模块,您可以查看其源代码。否则,您可以使用inspect.getsource

标签: python libraries


【解决方案1】:

标准库的主要 repo 托管在这里:https://github.com/python/cpython/blob/3.7/Lib/

这也可以在相同位置(即子文件夹 Lib)的典型 Python 安装中找到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-26
    • 1970-01-01
    • 2021-09-21
    相关资源
    最近更新 更多