Python code -> to C code

Duncan Booth duncan at
Wed Apr 30 13:06:03 CEST 2003

Thomas Heller <theller at> wrote in news:bryo1gj6.fsf at

> Normally this is used to implement "callback functions" in Python, to
> call functions like Windows' EnumWindows(), or to implement COM object
> method tables.
> Does this count as embedding? It seems so, although I have never seen it
> this way.

I think it counts as half of embedding. It lets you call Python from C, 
provided the C was called originally from Python. I don't see that it helps 
at all with the situation in my original posting which was calling Python 
from an otherwise purely C program.

I'm impressed by the example wrapping qsort. I can't think offhand of a way 
to achieve this easily in Pyrex. That is, Pyrex could easily wrap qsort to 
call a specific Python function for the comparison, but there isn't 
anywhere in the qsort callback to store state, and I can't see how you 
manage to convert a Python function into a C level function without some 
additional state.

Duncan Booth                                             duncan at
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

More information about the Python-list mailing list