Python C/API simple debugging

Philip Semanchuk philip at semanchuk.com
Wed Nov 26 09:34:35 EST 2008


On Nov 26, 2008, at 6:47 AM, k3xji wrote:

>> By the way for simple print-debugging, below works right now, I  
>> forgot
> to try that
> fprintf(stderr,"%d", key);


As a new extension developer myself, I'll pass along the following  
handy macro that I swiped from another extension (psycopg I think):

#ifdef DEBUG_ON
#define DPRINTF(fmt, args...) fprintf(stderr, "+++ " fmt, ## args)
#else
#define DPRINTF(fmt, args...)
#endif

You can use it in code like so:

DPRINTF("key == %d\n", key);


And then turn all of your debug statements on/off by recompiling with/ 
without the DEBUG_ON flag.


HTH
Philip



More information about the Python-list mailing list