Pyrex gets a perfect score.

Rick Ratzel rlratzel at siliconmetrics.com
Thu Apr 1 17:33:37 EST 2004


...just curious...did you look at Elmer
(http://elmer.sourceforge.net)?  Elmer generates a C interface to a
Python module.  No knowledge of the Python/C API is necessary, and the
resulting C interface resembles (as close as possible) the underlying
Python interface.  Take a look at:

http://elmer.sourceforge.net/examples.html

   The Elmer examples in this presentation might be helpful too:

http://elmer.sourceforge.net/PyCon04/elmer_pycon04.html

   ...as well as the source code for the examples:

http://elmer.sourceforge.net/PyCon04/Elmer_PyCon04.tgz

   Like you mentioned, since the underlying code is Python, it will
not be as fast as C.  However, Elmer allows you to easily prototype
new functionality in Python and later re-write it in C for speed,
similar to what you said.  The C interface looks "native", and the
generated header file can even be re-used in most cases when/if you
re-write in C.

   The presentation & example code has a C++ example, showing how
Python classes and types can be used "seamlessly" in C++ too.


Kyler Laird <Kyler at news.Lairds.org> wrote in message news:<lhntj1-u62.ln1 at snout.lairds.org>...
> I mentioned earlier that I started using Pyrex because I'm taking a
> computer vision course that requires all assignments to be submitted
> as C(++).  While I could write C it would hurt me to do so and
> certainly distract me from the computer vision aspects.  I like
> using Python these days and Pyrex looked like a good solution.
> 
> (BTW, on the last assignment I saw several messages from someone
> having difficulty with segfaults due to memory allocation problems.
> Grrr...  Time spent messing with pointers is not advancing one's
> understanding of computer vision.)
> 
> Here's one reaction I got on the subject:
> >  1. How is your teacher going to react when you hand in obfuscated-ish
> >  C code that depends on the whole Python interpreter _and_ PIL?
> 
> The bottom line is that I got a perfect score on all (seven) of my
> homework assignments.  At first, I spent way too much time on them -
> figuring out how to use Pyrex and also just having fun exploring
> possibilities that I wouldn't have considered if I'd used C.  Later,
> however, I found that I could start on the assignment the night
> before it's due and complete it in time.  In terms of time, it was
> still a good investment over this short period.
> 
> Most important, I had fun doing these assignments and I learned a
> lot from them.  I am confident that I would not have accomplished
> as much with C (from scratch).
> 
> Our project is going to require fast decoding of an image.  My
> homework solutions have been agonizingly slow.  There's a lot of
> room for optimizations and I'm looking forward to using Pyrex to
> prototype in Python and then replace pieces with C as needed.
> 
> I can certainly see how Pyrex could serve nicely beyond academic
> settings.  Is it a way to sneak Python into projects that are
> "strictly C"?  Sure, it can work.  Can it free the developer to
> quickly experiment with new concepts without spending excessive
> effort on programming?  Definitely.  Is speed and ease of
> development sometimes more important than execution speed.  Yup.
> Can Pyrex be used effectively as a path to a native C solution?
> We'll see, but I'm confident that it can.
> 
> Thank you, Pyrex!
> 
> --kyler



More information about the Python-list mailing list