Any pointers/advice to help learn CPython source?

nnorwitz at gmail.com nnorwitz at gmail.com
Thu May 18 03:07:42 EDT 2006


seberino at spawar.navy.mil wrote:
> Anyone have any good advice to someone interested in learning about
> innards of Python implementation?
>
> e.g. What is best place to start?
>
>        Where can I get a 10,000 ft. overview of general structure?
>
>        Anyone written docs on helping do this?
>
>        How did other people successfully make it through?

Depends on what you want to get out of it.  There are only a handful of
top level directories that are interesting:

 Include - include files
 Objects - all Python objects (list, dict, int, float, functions, and
many others)
 Python - core interpreter and other support facilities

 Lib - Python stdlib (Lib/test is the test suite)
 Modules - C extension modules
 Parser - simple parser/tokenizer

The last three probably aren't interesting.  However, if you are
interested in the GC (or SRE) implementation, then you should look
under Modules as gcmodule.c and _sre.c are there.  So are a bunch of
others.

Include/ isn't particularly interesting.  Objects/ isn't too
interesting either from the standpoint of learning about the
interpreter.  Although the object implementations may be interesting in
their own right.  Each object is in an unsurprising file named
something like:  listobject.c or intobject.c.

That leaves Python/ which is where the real innards are.  If you are
interested in the interpreter, then Python/ceval.c is pretty much it.
The compiler is primarly in Python/compile.c, but also see Python/ast.c
(2.5 only) and Python/symtable.c.  All the global builtin functions are
in Python/bltinmodule.c.  Import support is in Python/import.c.  Most
of the other files in Python/ are small and/or platform specific.  They
probably aren't as interesting in general.

n




More information about the Python-list mailing list