Python/C API: Python class instance information in C?

Alex Martelli aleax at aleax.it
Fri Mar 21 04:26:00 EST 2003


Bernt Ribbum wrote:

> Thanks Alex,

You're welcome!


> The trick was to use the Object Protocol -- there I can find anything I
> want.

Yes, I think that using the PyObject_... functions (the "abstract layer")
is most often preferable to going to the "concrete layer" functions that
require you to know about objects' types -- and sometimes, as in this case,
you may even have no realistic alternatives.  Moreover, the abstract layer
functions just about "let you program Pythonically in C" -- that makes it
easier to prototype some of the extension in Python and then translate it
faithfully, choosing concrete-layer functions only when they're MUCH more
convenient, or along bottlenecks where the last drop of performance may
need to be extracted (abstract-layer functions have more indirectness and
thus can't be quite as fast as concrete-layer ones for cases where they're
both equally well applicable).


> (And thanks for compiling the Python Cookbook. That one is invaluable
> sometimes ;-)

I'll gladly share these thanks with co-editor David Ascher, the other
dozen of Python experts who provided the excellent chapter introductions,
AND the more than 100 authors of the recipes -- a truly collective work!-)


Alex





More information about the Python-list mailing list