3 ms·
We have already done this but wrote plain C extensions. Actually C libraries with a clean interface, then wrapped them in Python extensions as well. With C and
by rdtsc 16y ago
We have already done this but wrote plain C extensions. Actually C libraries with a clean interface, then wrapped them in Python extensions as well.
With C and Python you get to play on both ends of the spectrum -- concise clear code, and high performance code with C.
- mace 16y agoPure C extensions will give you the best performance. If you write really modular C code, interop with it and Python is really clean. Cython is interesting, but as cited, there are also some limitations and caveats. See http://docs.cython.org/src/userguide/limitations.html http://docs.cython.org/src/userguide/limitations.html and http://docs.cython.org/src/tutorial/caveats.html http://docs.cython.org/src/tutorial/caveats.html
- swolchok 16y agoCython is not a bad story for C interop, though. See e.g. pyevent (http://code.google.com/p/pyevent/ http://code.google.com/p/pyevent/), which provides Python bindings to libevent. Be warned: until there's a new release of pyevent (0.4), you should, in my opinion, use the SVN version.
- mturmon 16y agoI very much agree with this. Especially if you use similar C library interfacing styles, you can reuse or abstract out the glue parts easily. About playing on both sides of the efficiency/expressiveness spectrum, the important thing is to be sure to do real benchmarks so you only drop down into C when it pays off. Sometimes, the reasons are not just efficiency -- you may already have C code that does the right thing.