This is an old copy of the Python FAQ. The information here may be outdated.

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:

  1. modules written in Python (.py);

  2. modules written in C and dynamically loaded (.dll, .pyd, .so, .sl, etc);

  3. 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.

CATEGORY: library

 

A Django site. rendered by a django application. hosted by webfaction.