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.
For a pure python module you can find the source by looking at
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
You can also find the latest Mercurial version on the web at https://hg.python.org/cpython/file/tip/Modules/_datetimemodule.c
python -v from the command line should tell you what is being imported and from where. This works for me on Windows and Mac OS X.
C:\>python -v # installing zipimport hook import zipimport # builtin # installed zipimport hook # C:\Python24\lib\site.pyc has bad mtime import site # from C:\Python24\lib\site.py # wrote C:\Python24\lib\site.pyc # C:\Python24\lib\os.pyc has bad mtime import os # from C:\Python24\lib\os.py # wrote C:\Python24\lib\os.pyc import nt # builtin # C:\Python24\lib\ntpath.pyc has bad mtime ...
I'm not sure what those bad mtime's are on my install!