Where is the math.py (socket.py, regex.py, etc.) source file?
If you can’t find a source file for a module it may be a builtin or dynamically loaded module implemented in C, C++ or other compiled language. In this case you may not have the source file or it may be something like mathmodule.c, somewhere in a C source directory (not on the Python Path).
There are (at least) three kinds of modules in Python:
modules written in Python (.py);
modules written in C and dynamically loaded (.dll, .pyd, .so, .sl, etc);
modules written in C and linked with the interpreter; to get a list of these, type:
import sys print sys.builtin_module_names
To quickly check where a module is located, import it and check the module’s __file__ attribute:
>>> import math >>> math.__file__ '/usr/lib/python2.4/lib-dynload/math.so' >>> import random >>> random.__file__ '/usr/lib/python2.4/random.pyc'
If this gives you an AttributeError exception, the module is built into the interpreter.