Reputation: 23013
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
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
Reputation: 1577
Source for builtins functions (like sum
, zip
, etc) are in http://hg.python.org/cpython/file/57c157be847f/Python/bltinmodule.c.
Upvotes: 6
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