如何找到 Python 模块源的位置? [英] How do I find the location of Python module sources?
问题描述
如何了解给定 Python 模块的源文件安装位置?Windows 上的方法与 Linux 上的方法不同吗?
How do I learn where the source file for a given Python module is installed? Is the method different on Windows than on Linux?
我特别想寻找 datetime
模块的来源,但我也对更一般的答案感兴趣.
I'm trying to look for the source of the datetime
module in particular, but I'm interested in a more general answer as well.
推荐答案
对于纯 python 模块,您可以通过查看 themodule.__file__
找到源代码.但是,datetime 模块是用 C 编写的,因此 datetime.__file__
指向一个 .so 文件(Windows 上没有 datetime.__file__
),因此,你看不到来源.
For a pure python module you can find the source by looking at themodule.__file__
.
The datetime module, however, is written in C, and therefore datetime.__file__
points to a .so file (there is no datetime.__file__
on Windows), and therefore, you can't see the source.
如果您下载 Python 源 tarball 并解压缩,则可以在 Modules 子目录中找到模块的代码.
If you download a python source tarball and extract it, the modules' code can be found in the Modules subdirectory.
比如你想找python 2.6的datetime代码,可以看
For example, if you want to find the datetime code for python 2.6, you can look at
Python-2.6/Modules/datetimemodule.c
您还可以在网络上找到最新的 Mercurial 版本,网址为https://hg.python.org/cpython/file/tip/Modules/_datetimemodule.c
You can also find the latest Mercurial version on the web at https://hg.python.org/cpython/file/tip/Modules/_datetimemodule.c
这篇关于如何找到 Python 模块源的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!