Best way of extending Python com or lnk or dll?

Courageous jkraska1 at san.rr.com
Tue Apr 24 21:10:39 EDT 2001


>Unless you're wrapping existing code, do new work in Python first.
>Then if you really, really must, and have no other choice.
>Take a look at a 'C' extension.
>Often it's not worth the head ach to code it in 'C'.

An old quote, who's origin I've forgotten: "premature
optimization is the root of all evil." Which is to say,
profile your code first, then consider external C functions
for the things which actually consume CPU time.

BTW, to the original poster: the more work your code
can do in C once it gets there, the better. Python carries
significant overhead in dispatching to your external code.
If you external function is meant to do very small amounts
of work over very frequent invocations, external functions
aren't as obvious a choice and the benefits aren't nearly
as dramatic as you predict.

Conversely, things which do very large amounts of work
can push Python programs to at-or-near C speeds when
done right. Calculations in Numeric Python (and friends)
come to mind.

C//




More information about the Python-list mailing list