NEWBIE: Extending Python with C

engsol at teleport.com engsol at teleport.com
Fri Nov 8 22:48:35 EST 2002


I've read the books, tried some code, and I still just don't get it.

If some kind soul can explain the (high level) process, I can figure out the details, I
think.

What I want to do is call (or invoke) a C exe  from Python, and return the results to
Python. Or pass values of some sort to the C exe, and again have Python trap the returned
results. I'm a long way from the concept of shared variables. <grin>

The first stumbling block is that the books offer examples of C code which don't seem to
have a main(). My compilers don't care for that too much. I took a quick look at SWIG, but
to be honest, I didn't understand how to use it. Again, I need the high level concept.

The second problem is the concept of translating PyObjects to C and vice versa. As I say,
I just don't get it yet.

The third problem is that the books spend one paragraph on the Python/C code, usually for
Linux, then three pages on reference counts. Do I really have to worry about them, or not?

I'm using Python 222 on NT. If I understood how to do  "Hello world" (in C, called from
Python), I might be able to go from there.

In case you're interested, the reason I need to learn this is that my company is in dire
need of a new software test tool. I'm convinced that Python is the right scripting
language for the testers, and will be best in terms of maintainabilty and enhancement, no
matter if the platform is NT/2000/Linux. We have a huge library of legacy C code which we
can re-use as is, assuming I can learn to marry Python and C.

 BTW, I'm a diehard Python convert! (But my family doesn't know yet, so keep it under your
hat please)

Thanks.....Norm



More information about the Python-list mailing list