Python's architecture

Terry Reedy tjreedy at home.com
Sat Sep 15 13:34:17 EDT 2001


"Jonas Bengtsson" <jonas.b at home.se> wrote in message
news:4e2ddb70.0109150319.37e94984 at posting.google.com...
> Now I finally got a source with an explanation of the architecture
of
> Python: http://wiki.cs.uiuc.edu/cs427/PYTHON

Thanks for posting this fairly recent writeup, which I don't remember
being referenced on the newsgroup before.  Cmments:

"The Module folder contains all of the core modules required for the
bare-bones Python system. "

It contains the modules written in C rather than Python.  Some are
truly core, other are peripheral and only there because written in C
for speed.  The os module, written in Python and therefore in the lib
directory for runtime importation, is much more core than, for
instance, the md5 module.

"Since Python is implemented entirely in ANSI C..."

This, of course, only applies to the 'standard' implementation.

"In the Python interpreter each component could be a standalone
program. By component we mean the tokenizer, parser, compiler, and
evaluator. In Python these components are integrated to achieve better
performance, but the underlying theme hasn't changed from
batch-sequential. "

However, in interactive mode, things work line (and dependent indented
suites) by line.

> But it would be nice to have some other sources...

The Python site and/or distribution have writeups on extending and
embedding Python which have some 'official' documentation of
internals.  There have been threads in the newsgroup with discussion
of particular topics such as garbage collection, internal code
optimization, and others.  These are now accessible thru
groups.google.com with some searching.  If you have one specific
interest, ask, and you will probably some references.

Another note: some details change with new releases, which makes "The
Architecture of C-Python" a changing target.  Their discription of
PyObjects and type objects based on 2.1 is slightlyt different from
what I remember reading 1.4 and 1.5.2 source and from what it is in
2.2.

> About reading the source code they state:
> "Constructing an architectural picture from only source code is very
> tedious work"

In reading the code, I seem to have had at least three advantages over
Jackson and Tan.

1. I did not write up anthing, which for me would have been tedium.
I'm glad that they did.

2. I don't have as many book-generated preconceptions to overcome.
("Concepts in the text books don't always map easily to real-world
systems. We continuously encountered our version of "interface
mismatch" while trying to apply the concepts in the books. It was much
harder than we thought. ")

3. I came to Python, as an alternative to learning C++, after 15 years
of C programming, so I am completely comfortable with CPython's
'traditional' style.  ("We like working with OO languages a lot more
than non-OO languages (i.e., C++ v. C)").

Terry J. Reedy







More information about the Python-list mailing list