port only a single method of class to C?
I have a class with few methods and I'm happy with the performance of all of them except one method. We want to port that to C++. However we don't want to spend too much time porting the whole class to C++, just that single method. Is thi开发者_Python百科s possible? How should I do it? Should it be in a blank class? Not in a class? What I want is to try to use the C version and if failed (other OS, missing pyd), load the Python version. Thank you.
Depending on the complexity of your code, you could look into using Weave, which is part of SciPy. It allows you to embed C/C++ code in your python module. There's a tutorial here.
Another option you could look at is Boost::Python, which may be a bit more complex to use.
精彩评论