[Python-Dev] #include "Python.h"

Chris Angelico rosuav at gmail.com
Sun Jan 29 11:20:10 EST 2012

On Mon, Jan 30, 2012 at 2:34 AM, Andrea Crotti
<andrea.crotti.0 at gmail.com> wrote:
> I have a newbie question about CPython.
> Looking at the C code I noted that for example in tupleobject.c there is
> only one include
> #include "Python.h"

For files like tupleobject.c there's often a corresponding
tupleobject.h in the Include directory - does that help?

> Python.h actually includes everything as far as I can I see so:
> - it's very hard with a not-enough smart editor to find out where the
>  not-locally defined symbols are actually defined (well sure that is
>  not a problem for most of the people)

Yep. I would recommend using grep for such things, if your editor
can't/won't help you. Or change editors, but that's not always an easy

> - if all the files include python.h, doesn't it generate very big object
>  files? Or is it not a problem since they are stripped out after?

As a general rule, object files aren't bloated by excessive .h
inclusion; all that's in the header files is declarations. Having
everything include everything can potentially slow compilation, but
with a modern computer, a modern compiler, and proper division of code
into multiple source files, that's not a significant concern. In any
case, the worst that can happen is overly-large intermediate (.o or
.obj) files; by the time the final binary is built, any duplicates
will have to have been "folded down" to one anyway.

Chris Angelico

More information about the Python-list mailing list