bdhar
bdhar

Reputation: 23013

Source code for Python's modules

Is it possible to view the source code of Python's functions like sum, zip and the like? I just want to know about the implementation.

Thanks.

Upvotes: 8

Views: 9228

Answers (4)

user3532274
user3532274

Reputation: 29

This will give you the location of the Python source code files on disk:

import sys
print(["%s %s" % (k,v) for k,v in sys,modules.items()] if k == "re")

On Windows, it is usually found on C:\python33\lib\. and on Linux it is /usr/python2.7/lib/....

Once there, you can view the .py files as you wish.

Upvotes: 0

neizod
neizod

Reputation: 1577

Source for builtins functions (like sum, zip, etc) are in http://hg.python.org/cpython/file/57c157be847f/Python/bltinmodule.c.

Upvotes: 6

Neel
Neel

Reputation: 21329

You cant see the code for the sum and zip because those are wrapper of c functions. But other module you can check on http://hg.python.org/cpython/file/2.7/Lib

Upvotes: 3

wim
wim

Reputation: 363616

You can download it here:

http://www.python.org/getit/source/

Upvotes: 7

Related Questions