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

Paul Moore p.f.moore at gmail.com
Sun Jan 29 19:34:49 CET 2012


On 29 January 2012 18:10, C. Titus Brown <ctb at msu.edu> wrote:
> python-dev isn't that inappropriate, IMO, but probably the best place to
> go with this discussion is python-ideas.  Could you repost over there?

I agree that python-dev isn't particularly appropriate, python-list is
probably your best bet. The python-ideas isn't really appropriate, as
this isn't a proposal for a change to Python, but rather a question
about how the Python C code is structured. That's always a grey area,
and I can see why the OP thought python-dev might be a reasonable
place.

Having said all that:

> 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)

Well, that's more of a question of what tools you use to edit/read
Python code. I guess you could view it as a trade-off between ease of
writing the core code and extensions (avoiding micromanagement of
headers, and being able to document #include "Python.h" as the
canonical way to get access to the Python API from C) versus tracking
down macro definitions and symbol declarations (and that's really only
for information, as the API is documented in the manuals anyway).

I don't use an editor that can automatically find the definitions, but
grep and the manuals does me fine.

> - 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?

That's more of a C/linker question, but generally .h files only
contain declarations and macros, and nothing that generates code. So
there is no impact on object code size if you include multiple .h
files, or too many, or whatever. So no, it doesn't generate big object
files.

Paul


More information about the Python-Dev mailing list