如何找到Python模块源的位置? [英] How do I find the location of Python module sources?

查看:127
本文介绍了如何找到Python模块源的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何了解给定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的日期时间代码,可以查看

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屋!

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