Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the location of Python module sources?

Tags:

python

module

How do I learn where the source file for a given Python module is installed? Is the method different on Windows than on Linux?

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.

like image 902
Daryl Spitzer Avatar asked Nov 06 '08 18:11

Daryl Spitzer


1 Answers

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.

If you download a python source tarball and extract it, the modules' code can be found in the Modules subdirectory.

For example, if you want to find the datetime code for python 2.6, you can look at

Python-2.6/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

like image 66
Moe Avatar answered Sep 28 '22 03:09

Moe