Calling a C program from a Python Script

Caleb Hattingh caleb1 at telkomsa.net
Thu Dec 9 23:05:06 EST 2004


Hi Brad

Not that I'm an expert but note:

1.  If you already know C, fair enough.  You should know what you are  
getting into then. I sure as heck don't know it very well at all and I'm  
not gonna make that time investment now.  MAYBE if I really really needed  
the extra speed (but this seems to arise more infrequently than one would  
imagine) for something where I couldn't interface with some existing  
binary library.

2.  The PythonForDelphi crowd makes the creation of native binary  
extensions with Delphi pathetically easy (which is about equivalent to the  
degree of complexity I can handle).  As I said in a previous post, C is  
not the only game in town for binary extensions.  Of course, I happen to  
already know ObjectPascal (Delphi) quite well, so for me it is a good fit  
- maybe not so much for you if pascal would be new for you.  If both  
pascal AND C are new for you, I suspect you will find Delphi a fair bit  
easier (& faster) to learn.  btw, Works with Kylix also.  I don't know  
about FPC.

3.  As someone said previously, some of the 'builtin' python functionality  
is compiled C anyway.  This point alone often makes it very difficult to  
qualify statements like 'python is slow'.  You could even start with the  
Cpython source for something like file access and see how you go with  
optimization, if *that* performance was not enough for you.

4. Nobody mentioned Pyrex yet, I think it kinda allows you to write C  
within your python scripts, and then handles that all intellligently,  
compiles the necessary bits, and so on - try a google search for the facts  
rather than my broken memory of features.

5. If all you are is curious about interfacing a C extension with Python -  
that's cool too.  I would be interested in hearing what to look out for in  
the learning stage of developing C-extensions, for when I am overcome by  
curiosity and feel the need to try it out.

Keep well
Caleb

> I just want to know the basics of using C and Python together when the  
> need arises, that's all, I don't want to write a book about what exactly  
> it is that I'm involved in.
>
> I'm going to take It's Me's advice and have a look at SWIG.
>
> Thank you,
>
> Brad




More information about the Python-list mailing list